bfdtest1 segfaults on hppa-hp-hpux10

Message ID 20190522090214.GU6820@bubble.grove.modra.org
State New
Headers show
Series
  • bfdtest1 segfaults on hppa-hp-hpux10
Related show

Commit Message

Alan Modra May 22, 2019, 9:02 a.m.
The archive element cache needs tidying when closing an archive element.
This patch fixes these failures:
-FAIL: ar long file names (bfdtest1)
-FAIL: ar thin archive (bfdtest1)
-FAIL: ar thin archive with nested archive (bfdtest1)

	* som.c (som_bfd_free_cached_info): Call
	_bfd_generic_close_and_cleanup.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/som.c b/bfd/som.c
index 640253ea9a..0d17b3278a 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -6695,25 +6695,25 @@  som_write_armap (bfd *abfd,
 static bfd_boolean
 som_bfd_free_cached_info (bfd *abfd)
 {
-  asection *o;
-
-  if (bfd_get_format (abfd) != bfd_object)
-    return TRUE;
+  if (bfd_get_format (abfd) == bfd_object)
+    {
+      asection *o;
 
 #define FREE(x) if (x != NULL) { free (x); x = NULL; }
-  /* Free the native string and symbol tables.  */
-  FREE (obj_som_symtab (abfd));
-  FREE (obj_som_stringtab (abfd));
-  for (o = abfd->sections; o != NULL; o = o->next)
-    {
-      /* Free the native relocations.  */
-      o->reloc_count = (unsigned) -1;
-      FREE (som_section_data (o)->reloc_stream);
-      /* Do not free the generic relocations as they are objalloc'ed.  */
-    }
+      /* Free the native string and symbol tables.  */
+      FREE (obj_som_symtab (abfd));
+      FREE (obj_som_stringtab (abfd));
+      for (o = abfd->sections; o != NULL; o = o->next)
+	{
+	  /* Free the native relocations.  */
+	  o->reloc_count = (unsigned) -1;
+	  FREE (som_section_data (o)->reloc_stream);
+	  /* Do not free the generic relocations as they are objalloc'ed.  */
+	}
 #undef FREE
+    }
 
-  return TRUE;
+  return _bfd_generic_close_and_cleanup (abfd);
 }
 
 /* End of miscellaneous support functions.  */