From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21303 invoked by alias); 14 Dec 2012 10:55:04 -0000 Received: (qmail 21201 invoked by uid 22791); 14 Dec 2012 10:54:55 -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 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; Fri, 14 Dec 2012 10:54:49 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBEAsjpM024639 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 14 Dec 2012 05:54:45 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBEAsidb024703; Fri, 14 Dec 2012 05:54:45 -0500 Message-ID: <50CB0574.7040406@redhat.com> Date: Fri, 14 Dec 2012 10:55: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 other memory leak in solib_target_current_sos References: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com> <50CA3784.2030706@redhat.com> <000301cdd9d0$0db345d0$2919d170$@muller@ics-cnrs.unistra.fr> <50CAF521.3040307@redhat.com> <000001cdd9e5$6868f6e0$393ae4a0$@muller@ics-cnrs.unistra.fr> In-Reply-To: <000001cdd9e5$6868f6e0$393ae4a0$@muller@ics-cnrs.unistra.fr> 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/msg00488.txt.bz2 On 12/14/2012 10:25 AM, Pierre Muller wrote: > I found another leak, down the same line, > solib_target_current_sos > calls target_read_stralloc > which as its name suggests allocates the result on the heap... > But that string was not freed in the current code... > > This patch fixes that leak. Thanks. > 2012-12-14 Pierre Muller > > * solib-target.c (solib_target_current_sos): Remove 'const' > qualifier from type of library_document local variable to be > able to free it and avoid a memory leak. > > Index: src/gdb/solib-target.c > =================================================================== > RCS file: /cvs/src/src/gdb/solib-target.c,v > retrieving revision 1.24 > diff -u -p -r1.24 solib-target.c > --- src/gdb/solib-target.c 4 Jan 2012 08:17:11 -0000 1.24 > +++ src/gdb/solib-target.c 14 Dec 2012 10:17:58 -0000 > @@ -246,7 +246,7 @@ static struct so_list * > solib_target_current_sos (void) > { > struct so_list *new_solib, *start = NULL, *last = NULL; > - const char *library_document; > + char *library_document; > VEC(lm_info_p) *library_list; > struct lm_info *info; > int ix; > @@ -261,7 +261,10 @@ solib_target_current_sos (void) > /* Parse the list. */ > library_list = solib_target_parse_libraries (library_document); > if (library_list == NULL) > - return NULL; > + { > + xfree (library_document); > + return NULL; > + } > > /* Build a struct so_list for each entry on the list. */ > for (ix = 0; VEC_iterate (lm_info_p, library_list, ix, info); ix++) > @@ -291,6 +294,9 @@ solib_target_current_sos (void) > /* Free the library list, but not its members. */ > VEC_free (lm_info_p, library_list); > > + /* Also free allocated library_document string. */ > + xfree (library_document); > + > return start; > } > Parsing XML, within solib_target_parse_libraries, may throw. Thus, a cleanup would be better: + old_chain = make_cleanup (xfree, library_document); library_list = solib_target_parse_libraries (library_document); + do_cleanups (old_chain); -- Pedro Alves