]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld compact eh-frame leak
authorAlan Modra <amodra@gmail.com>
Wed, 22 Jan 2025 23:53:48 +0000 (10:23 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 23 Jan 2025 05:08:50 +0000 (15:38 +1030)
u.compact.extries wasn't being freed anywhere.  Free it when
destroying the linker hash table.  Also free u.dwarf.aray there in
case errors result in the linker not getting to the slightly earlier
free in write_dwarf_eh_frame_hdr.

* elf-eh-frame.c (write_dwarf_eh_frame_hdr): Don't exit without
freeing u.dwarf.array.
* elflink.c (_bfd_elf_link_hash_table_free): Free u.compact.entries
and u.dwarf.array.

bfd/elf-eh-frame.c
bfd/elflink.c

index 08ffc5f1b4a113366db1657ca94a2709cef9a58f..78b3ecb5a7db42480b382356d81d3ff6a1de58b7 100644 (file)
@@ -2411,7 +2411,7 @@ write_dwarf_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info)
   struct elf_link_hash_table *htab;
   struct eh_frame_hdr_info *hdr_info;
   asection *sec;
-  bool retval = true;
+  bool retval = false;
 
   htab = elf_hash_table (info);
   hdr_info = &htab->eh_info;
@@ -2427,14 +2427,11 @@ write_dwarf_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info)
     size += 4 + hdr_info->u.dwarf.fde_count * 8;
   contents = (bfd_byte *) bfd_malloc (size);
   if (contents == NULL)
-    return false;
+    goto out;
 
   eh_frame_sec = bfd_get_section_by_name (abfd, ".eh_frame");
   if (eh_frame_sec == NULL)
-    {
-      free (contents);
-      return false;
-    }
+    goto out;
 
   memset (contents, 0, EH_FRAME_HDR_SIZE);
   /* Version.  */
@@ -2458,6 +2455,7 @@ write_dwarf_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info)
     }
   bfd_put_32 (abfd, encoded_eh_frame, contents + 4);
 
+  retval = true;
   if (contents[2] != DW_EH_PE_omit)
     {
       unsigned int i;
@@ -2510,9 +2508,10 @@ write_dwarf_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info)
                                 (file_ptr) sec->output_offset,
                                 sec->size))
     retval = false;
+ out:
   free (contents);
-
   free (hdr_info->u.dwarf.array);
+  hdr_info->u.dwarf.array = NULL;
   return retval;
 }
 
index 27b02dd404f739d9ad4b85db678cfbeb94390e4c..309b4d75094baf91b993f92c406100b6c8a36852 100644 (file)
@@ -8383,6 +8383,10 @@ _bfd_elf_link_hash_table_free (bfd *obfd)
       bfd_hash_table_free (htab->first_hash);
       free (htab->first_hash);
     }
+  if (htab->eh_info.frame_hdr_is_compact)
+    free (htab->eh_info.u.compact.entries);
+  else
+    free (htab->eh_info.u.dwarf.array);
   _bfd_generic_link_hash_table_free (obfd);
 }