From c3460201a64b641e3a2089b7fca7ae17a9ddfb85 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 9 Apr 2024 18:41:59 -0700 Subject: elf: Fix a memory leak in _bfd_elf_add_dynamic_entry Normally, the section contents is allocated by bfd_alloc which is freed when the object is closed. But the .dynamic section contents is allocated by bfd_realloc, which should be freed by calling free. Add a dynamic field to elf_link_hash_table for the .dynamic section and free its contents in _bfd_elf_link_hash_table_free. * elf-bfd.h (elf_link_hash_table): Add dynamic. * elflink.c (_bfd_elf_link_create_dynamic_sections): Set the dynamic field in elf_link_hash_table. (_bfd_elf_add_dynamic_entry): Use hash_table->dynamic. (_bfd_elf_strip_zero_sized_dynamic_sections): Likewise. (bfd_elf_add_dt_needed_tag): Likewise. (elf_finalize_dynstr): Likewise. (_bfd_elf_link_hash_table_free): Free htab->dynamic->contents. (bfd_elf_final_link): Use htab->dynamic. * elfxx-x86.c (_bfd_x86_elf_finish_dynamic_sections): Use htab->elf.dynamic. --- bfd/elf-bfd.h | 1 + 1 file changed, 1 insertion(+) (limited to 'bfd/elf-bfd.h') diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 85e6648..ef5dcb5 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -757,6 +757,7 @@ struct elf_link_hash_table asection *irelifunc; asection *dynsym; asection *srelrdyn; + asection *dynamic; }; /* Returns TRUE if the hash table is a struct elf_link_hash_table. */ -- cgit v1.1