From 370426d0da768345fb53683c803d6d5a20558065 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 16 Jun 2022 14:48:13 +0930 Subject: Always free matching vector from bfd_check_format_matches At least one place calling list_matching_formats failed to free the "matching" vector from bfd_check_format_matches afterwards. Fix that by calling free inside list_matching_formats. binutils/ * bucomm.c (list_matching_formats): Free arg. * addr2line.c (process_file): Adjust to suit. * ar.c (open_inarch, ranlib_touch): Likewise. * coffdump.c (main): Likewise. * nm.c (display_archive, display_file): Likewise. * objcopy.c (copy_file): Likewise. * objdump.c (display_object_bfd): Likewise. * size.c (display_bfd): Likewise. * srconv.c (main): Likewise. ld/ * ldlang.c (load_symbols): Free "matching". --- ld/ldlang.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ld') diff --git a/ld/ldlang.c b/ld/ldlang.c index f10557a..839535b 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -3056,7 +3056,11 @@ load_symbols (lang_input_statement_type *entry, /* See if the emulation has some special knowledge. */ if (ldemul_unrecognized_file (entry)) - return true; + { + if (err == bfd_error_file_ambiguously_recognized) + free (matching); + return true; + } if (err == bfd_error_file_ambiguously_recognized) { @@ -3066,6 +3070,7 @@ load_symbols (lang_input_statement_type *entry, " matching formats:"), entry->the_bfd); for (p = matching; *p != NULL; p++) einfo (" %s", *p); + free (matching); einfo ("%F\n"); } else if (err != bfd_error_file_not_recognized -- cgit v1.1