From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9566 invoked by alias); 11 May 2011 04:00:02 -0000 Received: (qmail 9440 invoked by uid 22791); 11 May 2011 04:00:01 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e24smtp03.br.ibm.com (HELO e24smtp03.br.ibm.com) (32.104.18.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 May 2011 03:59:46 +0000 Received: from /spool/local by e24smtp03.br.ibm.com with XMail ESMTP for from ; Wed, 11 May 2011 00:59:44 -0300 Received: from mailhub1.br.ibm.com ([9.18.232.109]) by e24smtp03.br.ibm.com ([10.172.0.139]) with XMail ESMTP; Wed, 11 May 2011 00:59:42 -0300 Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.8.31.93]) by mailhub1.br.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4B40TY41343602 for ; Wed, 11 May 2011 01:00:38 -0300 Received: from d24av02.br.ibm.com (loopback [127.0.0.1]) by d24av02.br.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4B3xDpe004288 for ; Wed, 11 May 2011 00:59:13 -0300 Received: from [9.12.225.42] ([9.12.225.42]) by d24av02.br.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p4B3xCT7004219 for ; Wed, 11 May 2011 00:59:12 -0300 Subject: [RFA] Fix memory leak in lookup_symtab From: Thiago Jung Bauermann To: gdb-patches ml Content-Type: text/plain; charset="UTF-8" Date: Wed, 11 May 2011 04:00:00 -0000 Message-ID: <1305086349.2308.84.camel@hactar> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit x-cbid: 11051103-9254-0000-0000-000005070E0C X-IsSubscribed: yes 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: 2011-05/txt/msg00268.txt.bz2 Hi, While working on the patch I just posted, I found this memory leak (I actually found more, but this was trivial to fix). It doesn't seem big, leaks at most 890 bytes in break.exp. I didn't check with other testcases. No regressions on ppc-linux and ppc64-linux. Ok? -- []'s Thiago Jung Bauermann IBM Linux Technology Center 2011-05-11 Thiago Jung Bauermann * symtab.c (lookup_symtab): Run cleanup before returning. diff --git a/gdb/symtab.c b/gdb/symtab.c index d98ac57..f6dc0e9 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -158,6 +158,9 @@ lookup_symtab (const char *name) struct objfile *objfile; char *real_path = NULL; char *full_path = NULL; + struct cleanup *cleanup; + + cleanup = make_cleanup (null_cleanup, NULL); /* Here we are interested in canonicalizing an absolute path, not absolutizing a relative path. */ @@ -177,6 +180,7 @@ got_symtab: { if (FILENAME_CMP (name, s->filename) == 0) { + do_cleanups (cleanup); return s; } @@ -189,6 +193,7 @@ got_symtab: if (fp != NULL && FILENAME_CMP (full_path, fp) == 0) { + do_cleanups (cleanup); return s; } } @@ -204,6 +209,7 @@ got_symtab: make_cleanup (xfree, rp); if (FILENAME_CMP (real_path, rp) == 0) { + do_cleanups (cleanup); return s; } } @@ -216,7 +222,10 @@ got_symtab: ALL_SYMTABS (objfile, s) { if (FILENAME_CMP (lbasename (s->filename), name) == 0) - return s; + { + do_cleanups (cleanup); + return s; + } } /* Same search rules as above apply here, but now we look thru the @@ -235,9 +244,15 @@ got_symtab: } if (s != NULL) - return s; + { + do_cleanups (cleanup); + return s; + } if (!found) - return NULL; + { + do_cleanups (cleanup); + return NULL; + } /* At this point, we have located the psymtab for this file, but the conversion to a symtab has failed. This usually happens