[v4,23/35] libctf: actually close bfds we have opened

Message ID 20190924135131.441906-24-nick.alcock@oracle.com
State New
Headers show
Series
  • CTF linking support
Related show

Commit Message

Nick Alcock Sept. 24, 2019, 1:51 p.m.
When we do a ctf_fdopen, we open things via bfd_fdopenr and set up a
hook to close the bfd again... but then we never actually call that hook
from anywhere, so we eventually leak every bfd we open.

Fix this by calling the hook (if set) in ctf_arc_close.

New in v3.

libctf/
	* ctf-archive.c (ctf_arc_close): Call ctfi_bfd_close if set.
	* ctf-open-bfd.c (ctf_bfdclose): Fix comment.
---
 libctf/ctf-archive.c  | 2 ++
 libctf/ctf-open-bfd.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

-- 
2.23.0.239.g28aa4420fd

Patch

diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index 8de11d6d583..979641cc1e7 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -436,6 +436,8 @@  ctf_arc_close (ctf_archive_t *arc)
   free ((void *) arc->ctfi_symsect.cts_data);
   /* Do not free the ctfi_strsect: it is bound to the bfd.  */
   free (arc->ctfi_data);
+  if (arc->ctfi_bfd_close)
+    arc->ctfi_bfd_close (arc);
   free (arc);
 }
 
diff --git a/libctf/ctf-open-bfd.c b/libctf/ctf-open-bfd.c
index da62463c35f..d50bd0b1ae2 100644
--- a/libctf/ctf-open-bfd.c
+++ b/libctf/ctf-open-bfd.c
@@ -66,7 +66,7 @@  ctf_new_archive_internal (int is_archive, struct ctf_archive *arc,
   return arci;
 }
 
-/* Free the BFD bits of a CTF file on ctf_file_close().  */
+/* Free the BFD bits of a CTF file on ctf_arc_close().  */
 
 static void
 ctf_bfdclose (struct ctf_archive_internal *arci)