public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: pdb: _bfd_generic_close_and_cleanup
Date: Fri, 23 Sep 2022 11:57:32 +0930	[thread overview]
Message-ID: <Yy0ZlFk9LQTSZ4bF@squeak.grove.modra.org> (raw)

Every format that might appear inside a generic archive needs to call
_bfd_generic_close_and_cleanup, so that the archive element lookup
htab can be tidied on closing an element.  Otherwise you get stale
entries in the htab pointing at freed and perhaps reused memory,
resulting in segfaults when the archive is closed.

Calling _bfd_generic_close_and_cleanup on close means tdata needs to
be set up too, since pdb claims to be of format bfd_archive.

	* pdb.c (pdb_close_and_cleanup): Define as
	_bfd_generic_close_and_cleanup.
	(pdb_archive_p): Set up tdata for bfd_archive format.

diff --git a/bfd/pdb.c b/bfd/pdb.c
index 67d7e73c655..14e1049d03c 100644
--- a/bfd/pdb.c
+++ b/bfd/pdb.c
@@ -54,6 +54,11 @@ pdb_archive_p (bfd *abfd)
       return NULL;
     }
 
+  void *tdata = bfd_zalloc (abfd, sizeof (struct artdata));
+  if (tdata == NULL)
+    return NULL;
+  bfd_ardata (abfd) = tdata;
+
   return _bfd_no_cleanup;
 }
 
@@ -755,7 +760,7 @@ pdb_write_contents (bfd *abfd)
 #define pdb_new_section_hook _bfd_generic_new_section_hook
 #define pdb_get_section_contents _bfd_generic_get_section_contents
 #define pdb_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
-#define pdb_close_and_cleanup _bfd_bool_bfd_true
+#define pdb_close_and_cleanup _bfd_generic_close_and_cleanup
 
 #define pdb_slurp_armap _bfd_noarchive_slurp_armap
 #define pdb_slurp_extended_name_table _bfd_noarchive_slurp_extended_name_table

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2022-09-23  2:27 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=Yy0ZlFk9LQTSZ4bF@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).