From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30548 invoked by alias); 14 Dec 2012 07:53:17 -0000 Received: (qmail 30532 invoked by uid 22791); 14 Dec 2012 07:53:16 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,MSGID_MULTIPLE_AT,TW_CP,TW_QX X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.156) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Dec 2012 07:53:11 +0000 Received: from md13.u-strasbg.fr (md13.u-strasbg.fr [130.79.200.248]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qBE7r5KM011672 ; Fri, 14 Dec 2012 08:53:05 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms13.u-strasbg.fr [130.79.204.113]) by md13.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qBE7r4CU029381 ; Fri, 14 Dec 2012 08:53:04 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qBE7r38e004639 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) ; Fri, 14 Dec 2012 08:53:03 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: "'Pedro Alves'" Cc: References: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com> <50CA3784.2030706@redhat.com> In-Reply-To: <50CA3784.2030706@redhat.com> Subject: RE: [RFA] Fix memory leak in windows_xfer_shared_libraries Date: Fri, 14 Dec 2012 07:53:00 -0000 Message-ID: <000301cdd9d0$0db345d0$2919d170$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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/msg00480.txt.bz2 > -----Message d'origine----- > De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Pedro Alves > Envoy=E9=A0: jeudi 13 d=E9cembre 2012 21:16 > =C0=A0: Pierre Muller > Cc=A0: gdb-patches@sourceware.org > Objet=A0: Re: [RFA] Fix memory leak in windows_xfer_shared_libraries >=20 > 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 =3D obstack_finish (&obstack); > > len_avail =3D strlen (buf); > > if (offset >=3D len_avail) > > - return 0; > > - > > - if (len > len_avail - offset) > > + len=3D 0 > > + else if (len > len_avail - offset) > > len =3D len_avail - offset; > > - memcpy (readbuf, buf + offset, len); > > + if (len > 0) > > + memcpy (readbuf, buf + offset, len); > > >=20 > You can avoid the last if by writing as: >=20 > if (offset >=3D len_avail) > len =3D 0; > else > { > if (len > len_avail - offset) > len =3D len_avail - offset; > memcpy (readbuf, buf + offset, len); > } >=20 > I'd prefer that, but patch is okay either way. I committed with your modification. Thanks for the approval. > > obstack_free (&obstack, NULL); > > return len; >=20 > > > > 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 > > :( >=20 > 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. I was wondering if this would become a problem if we later add support for multiple inferior for windows-nat I vaguely remember that I tried to achieve this a long time ago... Anyhow, the memory leak is gone at least! Pierre=20=20