coff_close_and_cleanup
authorAlan Modra <amodra@gmail.com>
Sun, 29 Dec 2019 02:25:20 +0000 (12:55 +1030)
committerAlan Modra <amodra@gmail.com>
Sun, 29 Dec 2019 10:56:00 +0000 (21:26 +1030)
Fixes leaks in _bfd_coff_get_external_symbols and
_bfd_coff_read_string_table.

* coffcode.h (coff_close_and_cleanup): Redefine to..
* coffgen.c (_bfd_coff_close_and_cleanup): ..this.  New function.
* libcoff-in.h (_bfd_coff_close_and_cleanup): Declare.
* libcoff.h: Regenerate.

bfd/ChangeLog
bfd/coffcode.h
bfd/coffgen.c
bfd/libcoff-in.h
bfd/libcoff.h

index af2ddfa5e0cfe181c03c089b230a962e69f8e259..de79b5eb239455169039aa20a4b29413e094c88f 100644 (file)
@@ -1,3 +1,10 @@
+2019-12-29  Alan Modra  <amodra@gmail.com>
+
+       * coffcode.h (coff_close_and_cleanup): Redefine to..
+       * coffgen.c (_bfd_coff_close_and_cleanup): ..this.  New function.
+       * libcoff-in.h (_bfd_coff_close_and_cleanup): Declare.
+       * libcoff.h: Regenerate.
+
 2019-12-29  Hannes Domani  <ssbssa@yahoo.de>
            Alan Modra  <amodra@gmail.com>
 
index ac5312fdb03cf760629a4380786fe26e72f71bfa..7bf7d68e03d70e2466dc4f0f83640a129e235f7b 100644 (file)
@@ -5642,7 +5642,7 @@ static bfd_coff_backend_data bigobj_swap_table =
 #endif /* COFF_WITH_PE_BIGOBJ */
 
 #ifndef coff_close_and_cleanup
-#define coff_close_and_cleanup             _bfd_generic_close_and_cleanup
+#define coff_close_and_cleanup             _bfd_coff_close_and_cleanup
 #endif
 
 #ifndef coff_bfd_free_cached_info
index 7f26e18c4509167b54eac29046e47960211fdba1..57a18b02dc1dd10910a6a36db1d4a8ee63af0f8a 100644 (file)
@@ -3161,3 +3161,18 @@ bfd_coff_group_name (bfd *abfd, const asection *sec)
     return ci->name;
   return NULL;
 }
+
+bfd_boolean
+_bfd_coff_close_and_cleanup (bfd *abfd)
+{
+  if (abfd->format == bfd_object
+      && bfd_family_coff (abfd)
+      && coff_data (abfd) != NULL)
+    {
+      obj_coff_keep_syms (abfd) = FALSE;
+      obj_coff_keep_strings (abfd) = FALSE;
+      if (!_bfd_coff_free_symbols (abfd))
+       return FALSE;
+    }
+  return _bfd_generic_close_and_cleanup (abfd);
+}
index 031622f0187ff62b124c53a048b64eb929610356..a4623dd903f4d33e330c7ab0ff052193c7a32d6a 100644 (file)
@@ -367,6 +367,8 @@ extern bfd_vma bfd_coff_reloc16_get_value
   (arelent *, struct bfd_link_info *, asection *);
 extern void bfd_perform_slip
   (bfd *, unsigned int, asection *, bfd_vma);
+extern bfd_boolean _bfd_coff_close_and_cleanup
+  (bfd *);
 
 /* Functions and types in cofflink.c.  */
 
index 093f1b4159474eff1c3ed706684f1bf3bc6bc197..e9cade86bbbd2a105618ba200546a3cc6f6150f8 100644 (file)
@@ -371,6 +371,8 @@ extern bfd_vma bfd_coff_reloc16_get_value
   (arelent *, struct bfd_link_info *, asection *);
 extern void bfd_perform_slip
   (bfd *, unsigned int, asection *, bfd_vma);
+extern bfd_boolean _bfd_coff_close_and_cleanup
+  (bfd *);
 
 /* Functions and types in cofflink.c.  */