public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR30060, ASAN error in bfd_cache_close
Date: Tue, 31 Jan 2023 15:21:33 +1030	[thread overview]
Message-ID: <Y9ieVWMZ5oxFqZJJ@squeak.grove.modra.org> (raw)

After bfd_close nothing should access bfd memory.  Now that bfd_close
always tidies up even after an error, attempting to tidy the cached
bfd list by calling bfd_cache_close is wrong and not needed.

	PR 30060
	* ar.c (remove_output): Don't call bfd_cache_close.
	(output_bfd): Delete.
	* arsup.c (ar_end): Call bfd_close_all_done, not bfd_cache_close.

diff --git a/binutils/ar.c b/binutils/ar.c
index f8b161aaf5a..2c901ca327c 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -431,15 +431,12 @@ normalize (const char *file, bfd *abfd)
 
 static const char *output_filename = NULL;
 static FILE *output_file = NULL;
-static bfd *output_bfd = NULL;
 
 static void
 remove_output (void)
 {
   if (output_filename != NULL)
     {
-      if (output_bfd != NULL)
-	bfd_cache_close (output_bfd);
       if (output_file != NULL)
 	fclose (output_file);
       unlink_if_ordinary (output_filename);
@@ -1272,8 +1269,6 @@ write_archive (bfd *iarch)
       bfd_fatal (old_name);
     }
 
-  output_bfd = obfd;
-
   bfd_set_format (obfd, bfd_archive);
 
   /* Request writing the archive symbol table unless we've
@@ -1303,7 +1298,6 @@ write_archive (bfd *iarch)
   if (!bfd_close (obfd))
     bfd_fatal (old_name);
 
-  output_bfd = NULL;
   output_filename = NULL;
 
   /* We don't care if this fails; we might be creating the archive.  */
diff --git a/binutils/arsup.c b/binutils/arsup.c
index 8ffb5f34a2d..744a8d423af 100644
--- a/binutils/arsup.c
+++ b/binutils/arsup.c
@@ -469,8 +469,9 @@ ar_end (void)
 {
   if (obfd)
     {
-      bfd_cache_close (obfd);
-      unlink (bfd_get_filename (obfd));
+      const char *filename = bfd_get_filename (obfd);
+      bfd_close_all_done (obfd);
+      unlink (filename);
     }
 }
 

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-01-31  4:51 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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=Y9ieVWMZ5oxFqZJJ@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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).