From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12176 invoked by alias); 13 Dec 2012 11:23:25 -0000 Received: (qmail 12166 invoked by uid 22791); 13 Dec 2012 11:23:24 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,MSGID_MULTIPLE_AT,TW_CP X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.152) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Dec 2012 11:23:19 +0000 Received: from md15.u-strasbg.fr (md15.u-strasbg.fr [130.79.200.204]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qBDBNHon027389 for ; Thu, 13 Dec 2012 12:23:17 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms11.u-strasbg.fr [130.79.204.111]) by md15.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qBDBNHnX030827 for ; Thu, 13 Dec 2012 12:23:17 +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 qBDBNHPa027587 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Thu, 13 Dec 2012 12:23:17 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: References: <008a01cdd922$971dcb00$c5596100$@muller@ics-cnrs.unistra.fr> In-Reply-To: <008a01cdd922$971dcb00$c5596100$@muller@ics-cnrs.unistra.fr> Subject: RE: [RFA] Fix memory leak in windows_xfer_shared_libraries Date: Thu, 13 Dec 2012 11:23:00 -0000 Message-ID: <008d01cdd924$41261fc0$c3725f40$@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/msg00438.txt.bz2 Whoops,=20 I forgot to test my patch :( Once again, got bitten by a difference in syntax between C and pascal... a semicolon was missing before the else keyword... Sorry about that, Pierre=20=20 > -----Message d'origine----- > De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Pierre Muller > Envoy=E9=A0: jeudi 13 d=E9cembre 2012 12:11 > =C0=A0: gdb-patches@sourceware.org > Objet=A0: [RFA] Fix memory leak in windows_xfer_shared_libraries >=20 > The current mechanism of getting the list of DLLs when command > infl dll > is given to gdb prompt, > info_shared_library function in solib.c calls > windows_xfer_shared_libraries in windows-nat.c >=20 > using target_read_stralloc, which calls target_read_alloc_1. >=20 > That function reiterates calls to target_read_partial > until the number of transferred bytes is zero... >=20 > This results even if the buffer is large enough to contain all data at > first > call in a second call in which the same xml answer is computed again, > and nothing is done, because the offset correspond to the end of the > resulting > string. >=20 > The current code has a memory leak that is fixed by the patch below. >=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 Fixed patch: 2012-12-13 Pierre Muller * windows-nat.c (windows_xfer_shared_libraries): Avoid memory leak when OFFSET >=3D LEN_AVAIL. Index: windows-nat.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.236 diff -u -p -r1.236 windows-nat.c --- 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 obstack_free (&obstack, NULL); return len;