This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/5] fix the archive hash table memory leak


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]