PR24891, objdump memory leaks when parsing malformed archive
[deliverable/binutils-gdb.git] / bfd / archive.c
index 68a92a3e36314959661ae44bfcf6e2cc3bf2fb64..3baf83d40ca18689283b4132468d72c1835aa7f4 100644 (file)
@@ -734,7 +734,8 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos)
   /* Copy is_linker_input.  */
   n_bfd->is_linker_input = archive->is_linker_input;
 
-  if (_bfd_add_bfd_to_archive_cache (archive, filepos, n_bfd))
+  if (archive->no_element_cache
+      || _bfd_add_bfd_to_archive_cache (archive, filepos, n_bfd))
     return n_bfd;
 
   free (new_areldata);
@@ -885,6 +886,7 @@ bfd_generic_archive_p (bfd *abfd)
   if (abfd->target_defaulted && bfd_has_map (abfd))
     {
       bfd *first;
+      unsigned int save;
 
       /* This archive has a map, so we may presume that the contents
         are object files.  Make sure that if the first file in the
@@ -897,14 +899,17 @@ bfd_generic_archive_p (bfd *abfd)
         normal archive, regardless of the format of the object files.
         We do accept an empty archive.  */
 
+      save = abfd->no_element_cache;
+      abfd->no_element_cache = 1;
       first = bfd_openr_next_archived_file (abfd, NULL);
+      abfd->no_element_cache = save;
       if (first != NULL)
        {
          first->target_defaulted = FALSE;
          if (bfd_check_format (first, bfd_object)
              && first->xvec != abfd->xvec)
            bfd_set_error (bfd_error_wrong_object_format);
-         /* And we ought to close `first' here too.  */
+         bfd_close (first);
        }
     }
 
@@ -974,7 +979,6 @@ do_slurp_bsd_armap (bfd *abfd)
       goto byebye;
     }
 
-  ardata->cache = 0;
   rbase = raw_armap + BSD_SYMDEF_COUNT_SIZE;
   stringbase = ((char *) rbase
                + ardata->symdef_count * BSD_SYMDEF_SIZE
@@ -2236,6 +2240,7 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
   long syms_max = 0;
   bfd_boolean ret;
   bfd_size_type amt;
+  static bfd_boolean report_plugin_err = TRUE;
 
   /* Dunno if this is the best place for this info...  */
   if (elength != 0)
@@ -2270,6 +2275,14 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
          long symcount;
          long src_count;
 
+         if (current->lto_slim_object && report_plugin_err)
+           {
+             report_plugin_err = FALSE;
+             _bfd_error_handler
+               (_("%pB: plugin needed to handle lto object"),
+                current);
+           }
+
          storage = bfd_get_symtab_upper_bound (current);
          if (storage < 0)
            goto error_return;
@@ -2322,10 +2335,14 @@ _bfd_compute_and_write_armap (bfd *arch, unsigned int elength)
                          && syms[src_count]->name[1] == '_'
                          && strcmp (syms[src_count]->name
                                     + (syms[src_count]->name[2] == '_'),
-                                    "__gnu_lto_slim") == 0)
-                       _bfd_error_handler
-                         (_("%pB: plugin needed to handle lto object"),
-                          current);
+                                    "__gnu_lto_slim") == 0
+                         && report_plugin_err)
+                       {
+                         report_plugin_err = FALSE;
+                         _bfd_error_handler
+                           (_("%pB: plugin needed to handle lto object"),
+                            current);
+                       }
                      namelen = strlen (syms[src_count]->name);
                      amt = sizeof (char *);
                      map[orl_count].name = (char **) bfd_alloc (arch, amt);
This page took 0.033793 seconds and 4 git commands to generate.