[20/21] Fix free() of in-use memory when handling archives

Richard Sandiford richards@transitive.com
Tue Mar 10 14:51:00 GMT 2009


xcoff_link_check_archive_element tries to be a good citizen and free
symbol tables for unneeded archive members.  The problem is that it
can be called twice for the same member (if the same library is listed
twice on the command line).  The second call can then end up freeing
information that was entered into the hash table by the first call.

OK to install?

Richard


bfd/
	* xcofflink.c (xcoff_link_check_archive_element): Only free the
	symbol table if it was created by the current call.

Index: bfd/xcofflink.c
===================================================================
--- bfd/xcofflink.c	2009-03-10 13:54:27.000000000 +0000
+++ bfd/xcofflink.c	2009-03-10 13:54:49.000000000 +0000
@@ -2149,6 +2149,9 @@ xcoff_link_check_archive_element (bfd *a
 				  struct bfd_link_info *info,
 				  bfd_boolean *pneeded)
 {
+  bfd_boolean keep_syms_p;
+
+  keep_syms_p = (obj_coff_external_syms (abfd) != NULL);
   if (! _bfd_coff_get_external_symbols (abfd))
     return FALSE;
 
@@ -2159,9 +2162,11 @@ xcoff_link_check_archive_element (bfd *a
     {
       if (! xcoff_link_add_symbols (abfd, info))
 	return FALSE;
+      if (info->keep_memory)
+	keep_syms_p = TRUE;
     }
 
-  if (! info->keep_memory || ! *pneeded)
+  if (!keep_syms_p)
     {
       if (! _bfd_coff_free_symbols (abfd))
 	return FALSE;



More information about the Binutils mailing list