PowerPC: Don't generate unused section symbols
[binutils-gdb.git] / bfd / format.c
index 61f26c6042ae3b3f957951c793cae12d1b1e3811..43bb34135e95f2a8d3a231b7021aa82de17ce8ad 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic BFD support for file formats.
-   Copyright (C) 1990-2020 Free Software Foundation, Inc.
+   Copyright (C) 1990-2021 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -500,8 +500,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
       if (abfd->direction == both_direction)
        abfd->output_has_begun = TRUE;
 
-      if (matching_vector)
-       free (matching_vector);
+      free (matching_vector);
       if (preserve_match.marker != NULL)
        bfd_preserve_finish (abfd, &preserve_match);
       bfd_preserve_finish (abfd, &preserve);
@@ -515,10 +514,11 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
     err_unrecog:
       bfd_set_error (bfd_error_file_not_recognized);
     err_ret:
+      if (cleanup)
+       cleanup (abfd);
       abfd->xvec = save_targ;
       abfd->format = bfd_unknown;
-      if (matching_vector)
-       free (matching_vector);
+      free (matching_vector);
       if (preserve_match.marker != NULL)
        bfd_preserve_finish (abfd, &preserve_match);
       bfd_preserve_restore (abfd, &preserve);
@@ -542,8 +542,10 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
          *(const char **) &matching_vector[match_count] = name;
        }
     }
-  else if (matching_vector)
+  else
     free (matching_vector);
+  if (cleanup)
+    cleanup (abfd);
   if (preserve_match.marker != NULL)
     bfd_preserve_finish (abfd, &preserve_match);
   bfd_preserve_restore (abfd, &preserve);