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.
This commit is contained in:
Alan Modra 2025-01-20 17:41:56 +10:30
parent c785932bb5
commit bf2da5d57d
3 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -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"));

View File

@ -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