]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
elf: Fix a memory leak in _bfd_elf_add_dynamic_entry
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 10 Apr 2024 01:41:59 +0000 (18:41 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 11 Apr 2024 02:50:01 +0000 (19:50 -0700)
commitc3460201a64b641e3a2089b7fca7ae17a9ddfb85
treefbb669a56a9b501570ca833010d1cc1696b8a414
parentea3002bc4d2a3c8ad284041f8a7dd08472c3f5fa
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
bfd/elflink.c
bfd/elfxx-x86.c