From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31412 invoked by alias); 13 Dec 2012 20:16:21 -0000 Received: (qmail 31401 invoked by uid 22791); 13 Dec 2012 20:16:18 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CP,TW_QX X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Dec 2012 20:16:10 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBDKG6qi002133 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Dec 2012 15:16:06 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBDKG58A008842; Thu, 13 Dec 2012 15:16:05 -0500 Message-ID: <50CA3784.2030706@redhat.com> Date: Thu, 13 Dec 2012 20:16:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Pierre Muller CC: gdb-patches@sourceware.org Subject: Re: [RFA] Fix memory leak in windows_xfer_shared_libraries References: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com> In-Reply-To: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-12/txt/msg00471.txt.bz2 On 12/13/2012 11:11 AM, Pierre Muller wrote: > --- windows-nat.c 13 Nov 2012 09:46:10 -0000 1.236 > +++ windows-nat.c 13 Dec 2012 10:54:18 -0000 > @@ -2411,11 +2411,11 @@ windows_xfer_shared_libraries (struct ta > buf = obstack_finish (&obstack); > len_avail = strlen (buf); > if (offset >= len_avail) > - return 0; > - > - if (len > len_avail - offset) > + len= 0 > + else if (len > len_avail - offset) > len = len_avail - offset; > - memcpy (readbuf, buf + offset, len); > + if (len > 0) > + memcpy (readbuf, buf + offset, len); > You can avoid the last if by writing as: if (offset >= len_avail) len = 0; else { if (len > len_avail - offset) len = len_avail - offset; memcpy (readbuf, buf + offset, len); } I'd prefer that, but patch is okay either way. > obstack_free (&obstack, NULL); > return len; > > I was also wondering if it would not be better to keep the obstack in > between the two calls, but that would probably require some static variable > :( That'd be fine. We actually do that in some cases in gdbserver, like handle_qxfer_threads and handle_qxfer_traceframe_info. It just didn't look like worth it enough to bother when I initially wrote this. -- Pedro Alves