From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24157 invoked by alias); 1 Aug 2012 01:28:27 -0000 Received: (qmail 24149 invoked by uid 22791); 1 Aug 2012 01:28:26 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-pb0-f41.google.com (HELO mail-pb0-f41.google.com) (209.85.160.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 01 Aug 2012 01:28:13 +0000 Received: by pbbrp2 with SMTP id rp2so216978pbb.0 for ; Tue, 31 Jul 2012 18:28:13 -0700 (PDT) Received: by 10.68.218.101 with SMTP id pf5mr47617675pbc.60.1343784493335; Tue, 31 Jul 2012 18:28:13 -0700 (PDT) Received: from bubble.grove.modra.org ([115.187.252.19]) by mx.google.com with ESMTPS id wh7sm1388202pbc.33.2012.07.31.18.28.10 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 Jul 2012 18:28:12 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 30942EA30AD; Wed, 1 Aug 2012 10:58:07 +0930 (CST) Date: Wed, 01 Aug 2012 01:28:00 -0000 From: Alan Modra To: Alexis Naveros Cc: binutils@sourceware.org, bug-binutils@gnu.org Subject: Re: Memory leaks in libbfd, trace provided Message-ID: <20120801012807.GW3182@bubble.grove.modra.org> Mail-Followup-To: Alexis Naveros , binutils@sourceware.org, bug-binutils@gnu.org References: <56136.190.207.139.30.1343654535.squirrel@mail.glvortex.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56136.190.207.139.30.1343654535.squirrel@mail.glvortex.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00003.txt.bz2 On Mon, Jul 30, 2012 at 09:22:15AM -0400, Alexis Naveros wrote: > I have some code which is using libbfd (binutils 2.22) abundantly, and I > couldn't help but notice memory usage grow to a couple GB after a while. > I'm of course calling bfd_close() for every bfd opened, but some memory > allocated from within libbfd.so is never freed. Thanks for the report. I'm applying the following to mainline binutils. The patch will need to be applied by hand to binutils-2.22. * dwarf2.c (struct dwarf2_debug): Add close_on_cleanup. (_bfd_dwarf2_slurp_debug_info): Set close_on_cleanup if we open gnu_debuglink bfd. (_bfd_dwarf2_cleanup_debug_info): Act on close_on_cleanup. Index: bfd/dwarf2.c =================================================================== RCS file: /cvs/src/src/bfd/dwarf2.c,v retrieving revision 1.150 diff -u -p -r1.150 dwarf2.c --- bfd/dwarf2.c 26 Jul 2012 18:20:39 -0000 1.150 +++ bfd/dwarf2.c 1 Aug 2012 01:24:18 -0000 @@ -173,6 +173,9 @@ struct dwarf2_debug #define STASH_INFO_HASH_OFF 0 #define STASH_INFO_HASH_ON 1 #define STASH_INFO_HASH_DISABLED 2 + + /* True if we opened bfd_ptr. */ + bfd_boolean close_on_cleanup; }; struct arange @@ -3206,6 +3209,7 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, if (! stash) return FALSE; stash->debug_sections = debug_sections; + stash->syms = symbols; *pinfo = stash; @@ -3235,7 +3239,9 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, free (debug_filename); return FALSE; } + stash->close_on_cleanup = TRUE; } + stash->bfd_ptr = debug_bfd; /* There can be more than one DWARF2 info section in a BFD these days. First handle the easy case when there's only one. If @@ -3293,9 +3299,6 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, stash->info_ptr_end = stash->info_ptr + total_size; stash->sec = find_debug_info (debug_bfd, debug_sections, NULL); stash->sec_info_ptr = stash->info_ptr; - stash->syms = symbols; - stash->bfd_ptr = debug_bfd; - return TRUE; } @@ -3689,4 +3692,6 @@ _bfd_dwarf2_cleanup_debug_info (bfd *abf free (stash->dwarf_ranges_buffer); if (stash->info_ptr_memory) free (stash->info_ptr_memory); + if (stash->close_on_cleanup) + bfd_close (stash->bfd_ptr); } -- Alan Modra Australia Development Lab, IBM