From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12484 invoked by alias); 7 Mar 2011 19:45:28 -0000 Received: (qmail 12474 invoked by uid 22791); 7 Mar 2011 19:45:27 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,TW_BJ,TW_YM,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-outbound-2.vmware.com (HELO smtp-outbound-2.vmware.com) (65.115.85.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Mar 2011 19:45:23 +0000 Received: from mailhost4.vmware.com (mailhost4.vmware.com [10.16.67.124]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 337A11C008; Mon, 7 Mar 2011 11:45:22 -0800 (PST) Received: from msnyder-server.eng.vmware.com (promd-2s-dhcp138.eng.vmware.com [10.20.124.138]) by mailhost4.vmware.com (Postfix) with ESMTP id 26F6DC9E4C; Mon, 7 Mar 2011 11:45:22 -0800 (PST) Message-ID: <4D7535D1.8030601@vmware.com> Date: Mon, 07 Mar 2011 19:51:00 -0000 From: Michael Snyder User-Agent: Thunderbird 2.0.0.24 (X11/20101201) MIME-Version: 1.0 To: Joel Brobecker CC: "gdb-patches@sourceware.org" Subject: Re: [RFA] elfread.c (elf_symtab_read): Stop memory leak. References: <4D729E84.3050401@vmware.com> <20110307111540.GB30306@adacore.com> In-Reply-To: <20110307111540.GB30306@adacore.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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-03/txt/msg00487.txt.bz2 Joel Brobecker wrote: >> 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? Not one by one, but I batch them up, yes. > 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). Thanks, committed. > >> 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 > >