aboutsummaryrefslogtreecommitdiff
path: root/ld/pe-dll.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-06-14 14:24:50 +0930
committerAlan Modra <amodra@gmail.com>2023-06-14 14:24:50 +0930
commit6f860418d556d4e5492b3da9e1a52e4b85a85f3e (patch)
tree7d8223edf575df45e809a9d2068b518ac67086d6 /ld/pe-dll.c
parent48375c36dc59e3c0e6b9bf38f17f4692bddb578f (diff)
downloadbinutils-6f860418d556d4e5492b3da9e1a52e4b85a85f3e.zip
binutils-6f860418d556d4e5492b3da9e1a52e4b85a85f3e.tar.gz
binutils-6f860418d556d4e5492b3da9e1a52e4b85a85f3e.tar.bz2
asprintf memory leaks
A number of backends want to return bfd_reloc_dangerous messaqes from relocation special_function, and construct the message using asprintf. Such messages are not freed anywhere, leading to small memory leaks inside libbfd. To limit the leaks, I'd implemented a static buffer in the ppc backends that was freed before use in asprintf output. This patch extends that scheme to other backends using a shared static buffer and goes further in freeing the buffer on any bfd_close. The patch also fixes a few other cases where asprintf output was not freed after use. bfd/ * bfd.c (_input_error_msg): Make global and rename to.. (_bfd_error_buf): ..this. (bfd_asprintf): New function. (bfd_errmsg): Use bfd_asprintf. * opncls.c (bfd_close_all_done): Free _buf_error_buf. * elf32-arm.c (find_thumb_glue, find_arm_glue): Use bfd_asprintf. * elf32-nios2.c (nios2_elf32_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_unhandled_reloc): Likewise. * elf64-ppc.c (ppc64_elf_unhandled_reloc): Likewise. * elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Likewise. (riscv_elf_relocate_section): Likewise. * libbfd.h: Regenerate. gas/ * read.c (read_end): Free current_name and current_label. (do_s_func): Likewise on error path. strdup label. ld/ * pe-dll.c (make_head, make_tail, make_one), (make_singleton_name_thunk, make_import_fixup_entry), (make_runtime_pseudo_reloc), (pe_create_runtime_relocator_reference: Free oname after use.
Diffstat (limited to 'ld/pe-dll.c')
-rw-r--r--ld/pe-dll.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index e45ae10..371915a 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -2107,6 +2107,7 @@ make_head (bfd *parent)
tmp_seq++;
abfd = bfd_create (oname, parent);
+ free (oname);
bfd_find_target (pe_details->object_target, abfd);
bfd_make_writable (abfd);
@@ -2200,6 +2201,7 @@ make_tail (bfd *parent)
tmp_seq++;
abfd = bfd_create (oname, parent);
+ free (oname);
bfd_find_target (pe_details->object_target, abfd);
bfd_make_writable (abfd);
@@ -2392,6 +2394,7 @@ make_one (def_file_export *exp, bfd *parent, bool include_jmp_stub)
tmp_seq++;
abfd = bfd_create (oname, parent);
+ free (oname);
bfd_find_target (pe_details->object_target, abfd);
bfd_make_writable (abfd);
@@ -2586,6 +2589,7 @@ make_singleton_name_thunk (const char *import, bfd *parent)
tmp_seq++;
abfd = bfd_create (oname, parent);
+ free (oname);
bfd_find_target (pe_details->object_target, abfd);
bfd_make_writable (abfd);
@@ -2666,6 +2670,7 @@ make_import_fixup_entry (const char *name,
tmp_seq++;
abfd = bfd_create (oname, parent);
+ free (oname);
bfd_find_target (pe_details->object_target, abfd);
bfd_make_writable (abfd);
@@ -2724,6 +2729,7 @@ make_runtime_pseudo_reloc (const char *name ATTRIBUTE_UNUSED,
tmp_seq++;
abfd = bfd_create (oname, parent);
+ free (oname);
bfd_find_target (pe_details->object_target, abfd);
bfd_make_writable (abfd);
@@ -2816,6 +2822,7 @@ pe_create_runtime_relocator_reference (bfd *parent)
tmp_seq++;
abfd = bfd_create (oname, parent);
+ free (oname);
bfd_find_target (pe_details->object_target, abfd);
bfd_make_writable (abfd);