]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Re: ld plugin bfd_make_readable leak
authorAlan Modra <amodra@gmail.com>
Fri, 24 Jan 2025 23:45:58 +0000 (10:15 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 25 Jan 2025 00:22:07 +0000 (10:52 +1030)
Commit 3097045a18a8 runs into an abort in objalloc_free_block when the
memory being bfd_release'd wasn't bfd_alloc'd.  Fix that.

* coffgen.c (_bfd_coff_free_cached_info): Don't release
raw_syments when obj_coff_keep_raw_syms.
* libcoff-in.h (obj_coff_keep_raw_syms): Define.
(struct coff_tdata): Add keep_raw_syms.
* peicode.h (pe_ILF_build_a_bfd): Set obj_coff_keep_raw_syms.
* libcoff.h: Regenerate.

bfd/coffgen.c
bfd/libcoff-in.h
bfd/libcoff.h
bfd/peicode.h

index c4026e96afb7aaf09d292aa5cf1afb6223c8fc9d..c734f058892c0b065f71404b1c963aeacb568f38 100644 (file)
@@ -3299,11 +3299,13 @@ _bfd_coff_free_cached_info (bfd *abfd)
 
       /* Free raw syms, and any other data bfd_alloc'd after raw syms
         are read.  */
-      if (obj_raw_syments (abfd))
-       bfd_release (abfd, obj_raw_syments (abfd));
-      obj_raw_syments (abfd) = NULL;
-      obj_symbols (abfd) = NULL;
-      obj_convert (abfd) = NULL;
+      if (!obj_coff_keep_raw_syms (abfd) && obj_raw_syments (abfd))
+       {
+         bfd_release (abfd, obj_raw_syments (abfd));
+         obj_raw_syments (abfd) = NULL;
+         obj_symbols (abfd) = NULL;
+         obj_convert (abfd) = NULL;
+       }
     }
 
   return _bfd_generic_bfd_free_cached_info (abfd);
index 51f964c4fd223872babecf69a3364decd51f747d..1410b08f6ae0420468a48fcf6ac8eedb38b3ad06 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
 #define obj_relocbase(bfd)           (coff_data (bfd)->relocbase)
 #define obj_raw_syments(bfd)         (coff_data (bfd)->raw_syments)
 #define obj_raw_syment_count(bfd)     (coff_data (bfd)->raw_syment_count)
+#define obj_coff_keep_raw_syms(bfd)   (coff_data (bfd)->keep_raw_syms)
 #define obj_convert(bfd)             (coff_data (bfd)->conversion_table)
 #define obj_conv_table_size(bfd)      (coff_data (bfd)->conv_table_size)
 #define obj_coff_external_syms(bfd)   (coff_data (bfd)->external_syms)
@@ -91,6 +92,8 @@ typedef struct coff_tdata
      backend flag _bfd_coff_long_section_names.  */
   bool long_section_names;
 
+  /* If this is TRUE, raw_syments may not be released.  */
+  bool keep_raw_syms;
   /* If this is TRUE, the external_syms may not be freed.  */
   bool keep_syms;
   /* If this is TRUE, the strings may not be freed.  */
index 947dbeb67a087607901d67fac096c3ca74c67d16..d0cfd09709a42d6cb4dce1fbb47d9718e2171b5a 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
 #define obj_relocbase(bfd)           (coff_data (bfd)->relocbase)
 #define obj_raw_syments(bfd)         (coff_data (bfd)->raw_syments)
 #define obj_raw_syment_count(bfd)     (coff_data (bfd)->raw_syment_count)
+#define obj_coff_keep_raw_syms(bfd)   (coff_data (bfd)->keep_raw_syms)
 #define obj_convert(bfd)             (coff_data (bfd)->conversion_table)
 #define obj_conv_table_size(bfd)      (coff_data (bfd)->conv_table_size)
 #define obj_coff_external_syms(bfd)   (coff_data (bfd)->external_syms)
@@ -95,6 +96,8 @@ typedef struct coff_tdata
      backend flag _bfd_coff_long_section_names.  */
   bool long_section_names;
 
+  /* If this is TRUE, raw_syments may not be released.  */
+  bool keep_raw_syms;
   /* If this is TRUE, the external_syms may not be freed.  */
   bool keep_syms;
   /* If this is TRUE, the strings may not be freed.  */
index ad4f1963b9c8bc02f2e2125f61e521adc4d231a5..3a93e0087999421caecee9858e1290930d54c137 100644 (file)
@@ -1154,6 +1154,7 @@ pe_ILF_build_a_bfd (bfd *     abfd,
 
   obj_raw_syments (abfd) = vars.native_syms;
   obj_raw_syment_count (abfd) = vars.sym_index;
+  obj_coff_keep_raw_syms (abfd) = true;
 
   obj_coff_external_syms (abfd) = (void *) vars.esym_table;
   obj_coff_keep_syms (abfd) = true;