From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 3467E3858D33 for ; Thu, 16 Jun 2022 08:43:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3467E3858D33 Received: by mail-pl1-x62f.google.com with SMTP id k7so754510plg.7 for ; Thu, 16 Jun 2022 01:43:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=7VaAgdVr/s3l/6EryPrjYjBpOz/0gW4ebgm0OybzL18=; b=aw5sVBiggj971dRlDviBHGu4yYkw2mUgn/TZxQLooZcIPESsLqEBIvffspGhnY48Fn zSoA/4sLIn7gSnn11V1dXfX28vhqUj5YbJBFAN+fE1Cj9W86yBwR2OiUH9ezSD8bhSQj SzmKTyR3ErpF88AEI8yJo7/+3J1Fg+GlXUsEXCi6G1LaPqdZTd2ZIzdSxF69iWFcWtqa 6ip467h6/FanhO5K/uEdcyTeY37JW3nQX5yUQwzjGVqpmWJRkCFVrEodtCrsmU64EUKz syT4uvpFgbyJzrv3iwfqSeKrJtsPvLZ4btePOXMxavuxJFb5g0n2sf2TLUkA/jZTnRFB bMbw== X-Gm-Message-State: AJIora8TvOSL9YZ60A+mMyBpl5rVnNv/IdGkOIlNXwvTqX/RcGzK02IY MlrjFpx2T4mO7eNdpiT5m/7ifD5jcDU= X-Google-Smtp-Source: AGRyM1uDk1w2Xmku/tipsJSZXPSpH1cgCE2H5hHhOuQ1dKZG633bSbuBgLu1dwCRgAlQlRB96LN7YA== X-Received: by 2002:a17:903:249:b0:168:ecca:43e with SMTP id j9-20020a170903024900b00168ecca043emr3881345plh.14.1655368996516; Thu, 16 Jun 2022 01:43:16 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:fcd3:ded:3837:3147]) by smtp.gmail.com with ESMTPSA id t27-20020a62d15b000000b0051c31cc3ca7sm1166384pfl.4.2022.06.16.01.43.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 01:43:15 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 1BDD51140304; Thu, 16 Jun 2022 18:13:13 +0930 (ACST) Date: Thu, 16 Jun 2022 18:13:13 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Always free matching vector from bfd_check_format_matches Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jun 2022 08:43:20 -0000 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". diff --git a/binutils/addr2line.c b/binutils/addr2line.c index fd2ac80dacd..baf16716182 100644 --- a/binutils/addr2line.c +++ b/binutils/addr2line.c @@ -452,10 +452,7 @@ process_file (const char *file_name, const char *section_name, { bfd_nonfatal (bfd_get_filename (abfd)); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); xexit (1); } diff --git a/binutils/ar.c b/binutils/ar.c index 6f3f1d6946f..0fdf0679b1c 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -1037,10 +1037,7 @@ open_inarch (const char *archive_filename, const char *file) { bfd_nonfatal (archive_filename); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); xexit (1); } @@ -1615,10 +1612,7 @@ ranlib_touch (const char *archname) { bfd_nonfatal (archname); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); xexit (1); } diff --git a/binutils/bucomm.c b/binutils/bucomm.c index 5cf9de75ff7..fdc2209df9c 100644 --- a/binutils/bucomm.c +++ b/binutils/bucomm.c @@ -160,15 +160,17 @@ set_default_bfd_target (void) /* After a FALSE return from bfd_check_format_matches with bfd_get_error () == bfd_error_file_ambiguously_recognized, print - the possible matching targets. */ + the possible matching targets and free the list of targets. */ void -list_matching_formats (char **p) +list_matching_formats (char **matching) { fflush (stdout); fprintf (stderr, _("%s: Matching formats:"), program_name); + char **p = matching; while (*p) fprintf (stderr, " %s", *p++); + free (matching); fputc ('\n', stderr); } diff --git a/binutils/coffdump.c b/binutils/coffdump.c index d760a6ccb39..bccc395e5f8 100644 --- a/binutils/coffdump.c +++ b/binutils/coffdump.c @@ -541,10 +541,7 @@ main (int ac, char **av) bfd_nonfatal (input_file); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); exit (1); } diff --git a/binutils/nm.c b/binutils/nm.c index 539c5688425..49726eeb83b 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -1626,10 +1626,7 @@ display_archive (bfd *file) { bfd_nonfatal (bfd_get_filename (arfile)); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); } if (last_arfile != NULL) @@ -1686,10 +1683,7 @@ display_file (char *filename) { bfd_nonfatal (filename); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); retval = false; } diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 7ad39e854f0..df87712df98 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3925,15 +3925,9 @@ copy_file (const char *input_filename, const char *output_filename, int ofd, bfd_nonfatal_message (input_filename, NULL, NULL, NULL); if (obj_error == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (obj_matching); - free (obj_matching); - } + list_matching_formats (obj_matching); if (core_error == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (core_matching); - free (core_matching); - } + list_matching_formats (core_matching); status = 1; } diff --git a/binutils/objdump.c b/binutils/objdump.c index e8fa8ca154e..67824053527 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -5426,7 +5426,6 @@ display_object_bfd (bfd *abfd) { nonfatal (bfd_get_filename (abfd)); list_matching_formats (matching); - free (matching); return; } @@ -5445,10 +5444,7 @@ display_object_bfd (bfd *abfd) nonfatal (bfd_get_filename (abfd)); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); } static void diff --git a/binutils/size.c b/binutils/size.c index 86dc13e4740..710402537e5 100644 --- a/binutils/size.c +++ b/binutils/size.c @@ -337,7 +337,6 @@ display_bfd (bfd *abfd) { bfd_nonfatal (bfd_get_filename (abfd)); list_matching_formats (matching); - free (matching); return_code = 3; return; } @@ -360,10 +359,7 @@ display_bfd (bfd *abfd) bfd_nonfatal (bfd_get_filename (abfd)); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); return_code = 3; } diff --git a/binutils/srconv.c b/binutils/srconv.c index 6fc98bc49d5..d017edff788 100644 --- a/binutils/srconv.c +++ b/binutils/srconv.c @@ -1828,10 +1828,7 @@ main (int ac, char **av) bfd_nonfatal (input_file); if (bfd_get_error () == bfd_error_file_ambiguously_recognized) - { - list_matching_formats (matching); - free (matching); - } + list_matching_formats (matching); exit (1); } diff --git a/ld/ldlang.c b/ld/ldlang.c index f10557af842..839535bdb73 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 -- Alan Modra Australia Development Lab, IBM