[binutils-gdb] ld: add_archive_element leak
Alan Modra
amodra@sourceware.org
Tue Feb 17 00:46:11 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=07b863b55114fe982951e70b95553cf98e189b69
commit 07b863b55114fe982951e70b95553cf98e189b69
Author: Alan Modra <amodra@gmail.com>
Date: Tue Feb 17 11:15:29 2026 +1030
ld: add_archive_element leak
Commit 52fdc0531ea7 exposed other minor leaks. Fix one of them.
* ldmain.c (add_archive_element): Use stat_alloc for
lang_input_statement.
Diff:
---
ld/ldmain.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/ld/ldmain.c b/ld/ldmain.c
index b30abceb64f..afbf039b1e2 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -1379,14 +1379,14 @@ static bool
add_archive_element (struct bfd_link_info *info,
bfd *abfd,
const char *name,
- bfd **subsbfd ATTRIBUTE_UNUSED)
+ bfd **subsbfd)
{
lang_input_statement_type *input;
lang_input_statement_type *parent;
lang_input_statement_type orig_input;
- input = (lang_input_statement_type *)
- xcalloc (1, sizeof (lang_input_statement_type));
+ input = stat_alloc (sizeof (*input));
+ memset (input, 0, sizeof (*input));
input->header.type = lang_input_statement_enum;
input->filename = bfd_get_filename (abfd);
input->local_sym_name = bfd_get_filename (abfd);
@@ -1431,7 +1431,6 @@ add_archive_element (struct bfd_link_info *info,
/* We have already loaded this element, and are attempting to
load it again. This can happen when the archive map doesn't
match actual symbols defined by the element. */
- free (input);
bfd_set_error (bfd_error_malformed_archive);
return false;
}
More information about the Binutils-cvs
mailing list