aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2025-01-20 17:41:56 +1030
committerAlan Modra <amodra@gmail.com>2025-01-20 18:16:15 +1030
commitbf2da5d57d7532855e56538a4a7242c705b1d27d (patch)
tree0c409dd16e39296d98f037f97f50fec29c635f63
parentc785932bb5ae8f8b9e8857c6436e13f051710858 (diff)
downloadbinutils-bf2da5d57d7532855e56538a4a7242c705b1d27d.zip
binutils-bf2da5d57d7532855e56538a4a7242c705b1d27d.tar.gz
binutils-bf2da5d57d7532855e56538a4a7242c705b1d27d.tar.bz2
ldelf_before_allocation leak
ldelf_before_allocation is passed the audit and depaudit strings built from command line args, then possibly adds to the depaudit string, freeing the original. The new string isn't freed. Fix this leak by keeping the string attached to the static vars. * ldelf.c (ldelf_before_allocation): Pass char** for audit and depaudit. Adjust uses. * ldelf.h (ldelf_before_allocation): Update prototype. * gld${EMULATION_NAME}_before_allocation: Update call.
-rw-r--r--ld/emultempl/elf.em2
-rw-r--r--ld/ldelf.c6
-rw-r--r--ld/ldelf.h2
3 files changed, 5 insertions, 5 deletions
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index 777f720..9dcb52e 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -170,7 +170,7 @@ fragment <<EOF
static void
gld${EMULATION_NAME}_before_allocation (void)
{
- ldelf_before_allocation (audit, depaudit, ${ELF_INTERPRETER_NAME});
+ ldelf_before_allocation (&audit, &depaudit, ${ELF_INTERPRETER_NAME});
}
EOF
diff --git a/ld/ldelf.c b/ld/ldelf.c
index d627b55..f56a627 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1752,7 +1752,7 @@ ldelf_append_to_separated_string (char **to, char *op_arg)
sections, but before any sizes or addresses have been set. */
void
-ldelf_before_allocation (char *audit, char *depaudit,
+ldelf_before_allocation (char **audit, char **depaudit,
const char *default_interpreter_name)
{
const char *rpath;
@@ -1834,7 +1834,7 @@ ldelf_before_allocation (char *audit, char *depaudit,
}
if (cp != NULL && *cp != '\0')
- ldelf_append_to_separated_string (&depaudit, cp);
+ ldelf_append_to_separated_string (depaudit, cp);
cp = more ? ++cp2 : NULL;
}
@@ -1844,7 +1844,7 @@ ldelf_before_allocation (char *audit, char *depaudit,
if (! (bfd_elf_size_dynamic_sections
(link_info.output_bfd, command_line.soname, rpath,
- command_line.filter_shlib, audit, depaudit,
+ command_line.filter_shlib, *audit, *depaudit,
(const char * const *) command_line.auxiliary_filters,
&link_info, &sinterp)))
einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
diff --git a/ld/ldelf.h b/ld/ldelf.h
index a6498cf..e8b7c8c 100644
--- a/ld/ldelf.h
+++ b/ld/ldelf.h
@@ -30,7 +30,7 @@ extern void ldelf_after_open (int, int, int, int, int, const char *);
extern bool ldelf_setup_build_id (bfd *);
extern bool ldelf_setup_package_metadata (bfd *);
extern void ldelf_append_to_separated_string (char **, char *);
-extern void ldelf_before_allocation (char *, char *, const char *);
+extern void ldelf_before_allocation (char **, char **, const char *);
extern bool ldelf_open_dynamic_archive
(const char *, search_dirs_type *, lang_input_statement_type *);
extern lang_output_section_statement_type *ldelf_place_orphan