From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8769 invoked by alias); 7 Mar 2011 11:16:11 -0000 Received: (qmail 8756 invoked by uid 22791); 7 Mar 2011 11:16:09 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,TW_BJ,TW_YM X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Mar 2011 11:16:05 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 09C072BAADB; Mon, 7 Mar 2011 06:16:04 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id b4hBXRgNkX0o; Mon, 7 Mar 2011 06:16:03 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 91AA72BAADA; Mon, 7 Mar 2011 06:16:03 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id EA5921459AD; Mon, 7 Mar 2011 15:15:40 +0400 (RET) Date: Mon, 07 Mar 2011 11:20:00 -0000 From: Joel Brobecker To: Michael Snyder Cc: "gdb-patches@sourceware.org" Subject: Re: [RFA] elfread.c (elf_symtab_read): Stop memory leak. Message-ID: <20110307111540.GB30306@adacore.com> References: <4D729E84.3050401@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4D729E84.3050401@vmware.com> User-Agent: Mutt/1.5.20 (2009-06-14) 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-03/txt/msg00446.txt.bz2 > 2011-03-05 Michael Snyder > > * elfread.c (elf_symtab_read): Stop memory leak. I think that's OK. A little more nervous than usual, as I had to look through a fair bit of code. But you did run this change past the testsuite, right? Note that we could possibly be using alloca to avoid the use of heap allocation. However, as I have learnt the hard way in the past, it's a really bad idea to do so in a loop (one can exhaust the stack very effectively that way). > Index: elfread.c > =================================================================== > RCS file: /cvs/src/src/gdb/elfread.c,v > retrieving revision 1.103 > diff -u -p -r1.103 elfread.c > --- elfread.c 7 Jan 2011 19:36:16 -0000 1.103 > +++ elfread.c 5 Mar 2011 20:33:20 -0000 > @@ -242,6 +242,7 @@ elf_symtab_read (struct objfile *objfile > char *filesymname = ""; > struct dbx_symfile_info *dbx = objfile->deprecated_sym_stab_info; > int stripped = (bfd_get_symcount (objfile->obfd) == 0); > + struct cleanup *back_to = make_cleanup (null_cleanup, NULL); > > for (i = 0; i < number_of_symbols; i++) > { > @@ -464,6 +465,7 @@ elf_symtab_read (struct objfile *objfile > * max_index)); > sectinfo = (struct stab_section_info *) > xmalloc (size); > + make_cleanup (xfree, sectinfo); > memset (sectinfo, 0, size); > sectinfo->num_sections = max_index; > if (filesym == NULL) > @@ -572,6 +574,7 @@ elf_symtab_read (struct objfile *objfile > } > } > } > + do_cleanups (back_to); > } > > struct build_id -- Joel