[PATCH] elf: Fix a memory leak in _bfd_elf_add_dynamic_entry
Alan Modra
amodra@gmail.com
Wed Apr 10 23:50:23 GMT 2024
On Tue, Apr 09, 2024 at 06:41:59PM -0700, H.J. Lu wrote:
> 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.
OK.
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list