public inbox for
 help / color / mirror / Atom feed
From: Alan Modra <>
Subject: Confusion in coff_object_cleanup
Date: Sun, 27 Aug 2023 14:13:42 +0930	[thread overview]
Message-ID: <ZOrUfpz/> (raw)

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

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

diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index bf9633a2b33..91667267cbc 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -284,18 +284,15 @@ make_a_section_from_file (bfd *abfd,
 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);
diff --git a/bfd/peicode.h b/bfd/peicode.h
index 5ac6b0dc53f..e1d06606575 100644
--- a/bfd/peicode.h
+++ b/bfd/peicode.h
@@ -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);

Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-08-27  4:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZOrUfpz/ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).