aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf-bfd.h
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2024-04-09 18:41:59 -0700
committerH.J. Lu <hjl.tools@gmail.com>2024-04-10 19:50:01 -0700
commitc3460201a64b641e3a2089b7fca7ae17a9ddfb85 (patch)
treefbb669a56a9b501570ca833010d1cc1696b8a414 /bfd/elf-bfd.h
parentea3002bc4d2a3c8ad284041f8a7dd08472c3f5fa (diff)
downloadgdb-c3460201a64b641e3a2089b7fca7ae17a9ddfb85.zip
gdb-c3460201a64b641e3a2089b7fca7ae17a9ddfb85.tar.gz
gdb-c3460201a64b641e3a2089b7fca7ae17a9ddfb85.tar.bz2
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.
Diffstat (limited to 'bfd/elf-bfd.h')
-rw-r--r--bfd/elf-bfd.h1
1 files changed, 1 insertions, 0 deletions
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. */