From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5590 invoked by alias); 13 Dec 2012 11:11:32 -0000 Received: (qmail 5579 invoked by uid 22791); 13 Dec 2012 11:11:31 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,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.157) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Dec 2012 11:11:25 +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 qBDBBMs2045559 for ; Thu, 13 Dec 2012 12:11:23 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms12.u-strasbg.fr [130.79.204.112]) by md15.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id qBDBBMwl026047 for ; Thu, 13 Dec 2012 12:11:22 +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 qBDBBMHn010251 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Thu, 13 Dec 2012 12:11:22 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Subject: [RFA] Fix memory leak in windows_xfer_shared_libraries Date: Thu, 13 Dec 2012 11:11:00 -0000 Message-ID: <008a01cdd922$971dcb00$c5596100$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" 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/msg00437.txt.bz2 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 using target_read_stralloc, which calls target_read_alloc_1. That function reiterates calls to target_read_partial until the number of transferred bytes is zero... 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. The current code has a memory leak that is fixed by the patch below. 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 :( Pierre Muller GDB pascal language maintainer 2012-12-13 Pierre Muller * windows-nat.c (windows_xfer_shared_libraries): Avoid memory leak when OFFSET >= LEN_AVAIL. Index: windows-nat.c =================================================================== 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 = 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); obstack_free (&obstack, NULL); return len;