Confusion in coff_object_cleanup
authorAlan Modra <amodra@gmail.com>
Sun, 27 Aug 2023 03:27:16 +0000 (12:57 +0930)
committerAlan Modra <amodra@gmail.com>
Sun, 27 Aug 2023 04:27:42 +0000 (13:57 +0930)
A bfd_cleanup function needs to run when only tdata is correct for the
bfd.  The xvec may have changed during bfd_check_format and thus the
flavour may be incorrect.  The format won't have changed but checking
is superfluous.  (In contrast to _bfd_free_cached_info or
_close_and_cleanup where we do need to check things.)

Not getting this correct leaked comdat_hash.

Also, pe_ILF_cleanup ought to call coff_object_cleanup as do all PE
files.

* coffgen.c (coff_object_cleanup): Don't check bfd flavour or
format.
* peicode.h (pe_ILF_cleanup): Call coff_object_cleanup.

bfd/coffgen.c
bfd/peicode.h

index bf9633a2b33ea5a4b161e2d585a2fdda99ac92c7..91667267cbc88005107c6605ca82c9abdf91173c 100644 (file)
@@ -284,18 +284,15 @@ make_a_section_from_file (bfd *abfd,
 void
 coff_object_cleanup (bfd *abfd)
 {
-  if (bfd_family_coff (abfd) && bfd_get_format (abfd) == bfd_object)
+  struct coff_tdata *td = coff_data (abfd);
+  if (td != NULL)
     {
-      struct coff_tdata *td = coff_data (abfd);
-      if (td != NULL)
-       {
-         if (td->section_by_index)
-           htab_delete (td->section_by_index);
-         if (td->section_by_target_index)
-           htab_delete (td->section_by_target_index);
-         if (obj_pe (abfd) && pe_data (abfd)->comdat_hash)
-           htab_delete (pe_data (abfd)->comdat_hash);
-       }
+      if (td->section_by_index)
+       htab_delete (td->section_by_index);
+      if (td->section_by_target_index)
+       htab_delete (td->section_by_target_index);
+      if (obj_pe (abfd) && pe_data (abfd)->comdat_hash)
+       htab_delete (pe_data (abfd)->comdat_hash);
     }
 }
 
index 5ac6b0dc53f6249fe0ba9f2bd1e330df8e491eae..e1d066065757eaf8c22369a8180eb75a86d41d9a 100644 (file)
@@ -1180,6 +1180,8 @@ pe_ILF_build_a_bfd (bfd *     abfd,
 static void
 pe_ILF_cleanup (bfd *abfd)
 {
+  coff_object_cleanup (abfd);
+
   struct bfd_in_memory *bim = abfd->iostream;
   free (bim->buffer);
   free (bim);