public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/5] fix the archive hash table memory leak
@ 2012-08-03 14:54 Tom Tromey
  2012-08-07 13:46 ` nick clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2012-08-03 14:54 UTC (permalink / raw)
  To: Binutils Development

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/5] fix the archive hash table memory leak
  2012-08-03 14:54 [PATCH 1/5] fix the archive hash table memory leak Tom Tromey
@ 2012-08-07 13:46 ` nick clifton
  0 siblings, 0 replies; 2+ messages in thread
From: nick clifton @ 2012-08-07 13:46 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Binutils Development

Hi Tom,

> 	* 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

Approved and applied.

Note - there was a small problem with the patch: 
_bfd_delete_archive_data was being called on bfds which were not 
archives (and hence bfd_ardata() returned a pointer to a structure that 
was not a struct artdata).  I fixed this by adding a test of the format 
in _bfd_delete_bfd before calling _bfd_delete_archive_data.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-07 13:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03 14:54 [PATCH 1/5] fix the archive hash table memory leak Tom Tromey
2012-08-07 13:46 ` nick clifton

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).