public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Binutils Development <binutils@sourceware.org>
Subject: [PATCH 1/5] fix the archive hash table memory leak
Date: Fri, 03 Aug 2012 14:54:00 -0000	[thread overview]
Message-ID: <873944own2.fsf@fleche.redhat.com> (raw)

Currently, closing an archive BFD will leak the archive BFD hash
table.

This fixes the bug by arranging to delete the hash table when the BFD
is closed.

Another approach would be to allocate the hash table on the BFD
objalloc.  I chose not to do this because it results in a different
kind of leak when the hash table is resized.

	* archive.c (_bfd_delete_archive_data): New function.
	* libbfd-in.h (_bfd_delete_archive_data): Declare.
	* libbfd.h: Rebuild.
	* opncls.c (_bfd_delete_bfd): Call _bfd_delete_archive_data.
---
 bfd/archive.c   |   11 +++++++++++
 bfd/libbfd-in.h |    2 ++
 bfd/libbfd.h    |    2 ++
 bfd/opncls.c    |    1 +
 4 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/bfd/archive.c b/bfd/archive.c
index fe57755..8d02257 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -293,6 +293,17 @@ bfd_set_archive_head (bfd *output_archive, bfd *new_head)
   return TRUE;
 }
 
+/* Free the archive hash table, if it exists.  */
+
+void
+_bfd_delete_archive_data (bfd *abfd)
+{
+  struct artdata *ardata = bfd_ardata (abfd);
+
+  if (ardata && ardata->cache)
+    htab_delete (ardata->cache);
+}
+
 bfd *
 _bfd_look_for_bfd_in_cache (bfd *arch_bfd, file_ptr filepos)
 {
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index c424fe2..882ccaa 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -130,6 +130,8 @@ extern void bfd_release
 
 bfd * _bfd_create_empty_archive_element_shell
   (bfd *obfd);
+void _bfd_delete_archive_data
+  (bfd *abfd);
 bfd * _bfd_look_for_bfd_in_cache
   (bfd *, file_ptr);
 bfd_boolean _bfd_add_bfd_to_archive_cache
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index e74ce34..898e6fc 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -135,6 +135,8 @@ extern void bfd_release
 
 bfd * _bfd_create_empty_archive_element_shell
   (bfd *obfd);
+void _bfd_delete_archive_data
+  (bfd *abfd);
 bfd * _bfd_look_for_bfd_in_cache
   (bfd *, file_ptr);
 bfd_boolean _bfd_add_bfd_to_archive_cache
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 7c1d2f9..734717a 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -130,6 +130,7 @@ _bfd_new_bfd_contained_in (bfd *obfd)
 void
 _bfd_delete_bfd (bfd *abfd)
 {
+  _bfd_delete_archive_data (abfd);
   if (abfd->memory)
     {
       bfd_hash_table_free (&abfd->section_htab);
-- 
1.7.7.6

             reply	other threads:[~2012-08-03 14:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03 14:54 Tom Tromey [this message]
2012-08-07 13:46 ` nick clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873944own2.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).