aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfxx-x86.c
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/elfxx-x86.c
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/elfxx-x86.c')
-rw-r--r--bfd/elfxx-x86.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 7d189bc..725884e 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2715,7 +2715,7 @@ _bfd_x86_elf_finish_dynamic_sections (bfd *output_bfd,
return htab;
dynobj = htab->elf.dynobj;
- sdyn = bfd_get_linker_section (dynobj, ".dynamic");
+ sdyn = htab->elf.dynamic;
/* GOT is always created in setup_gnu_properties. But it may not be
needed. .got.plt section may be needed for static IFUNC. */