Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/3] Use auto_obstack in objfile
Date: Tue,  2 Aug 2022 14:14:58 -0600	[thread overview]
Message-ID: <20220802201459.2839634-3-tom@tromey.com> (raw)
In-Reply-To: <20220802201459.2839634-1-tom@tromey.com>

This changes objfile to use an auto_obstack.  This helps prevent
use-after-free bugs, because it ensures that anything allocated on the
objfile obstack will live past the point at which the registry object
is destroyed.
---
 gdb/objfiles.c | 7 -------
 gdb/objfiles.h | 2 +-
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 3db9135a64b..c92da7548b3 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -324,10 +324,6 @@ objfile::objfile (gdb_bfd_ref_ptr bfd_, const char *name, objfile_flags flags_)
 {
   const char *expanded_name;
 
-  /* We could use obstack_specify_allocation here instead, but
-     gdb_obstack.h specifies the alloc/dealloc functions.  */
-  obstack_init (&objfile_obstack);
-
   std::string name_holder;
   if (name == NULL)
     {
@@ -583,9 +579,6 @@ objfile::~objfile ()
       clear_current_source_symtab_and_line ();
   }
 
-  /* Free the obstacks for non-reusable objfiles.  */
-  obstack_free (&objfile_obstack, 0);
-
   /* Rebuild section map next time we need it.  */
   get_objfile_pspace_data (pspace)->section_map_dirty = 1;
 }
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index eb85ed478c6..ac45fa3980f 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -666,7 +666,7 @@ struct objfile
   /* Obstack to hold objects that should be freed when we load a new symbol
      table from this object file.  */
 
-  struct obstack objfile_obstack {};
+  auto_obstack objfile_obstack;
 
   /* Structure which keeps track of functions that manipulate objfile's
      of the same type as this objfile.  I.e. the function to read partial
-- 
2.34.1


  parent reply	other threads:[~2022-08-02 20:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02 20:14 [PATCH 0/3] Fix regressions caused by registry series Tom Tromey
2022-08-02 20:14 ` [PATCH 1/3] Use gdb_bfd_ref_ptr in objfile Tom Tromey
2022-08-02 20:14 ` Tom Tromey [this message]
2022-08-02 20:14 ` [PATCH 3/3] Use unique_ptr to destroy per-bfd object Tom Tromey
2022-08-03 18:02 ` [PATCH 0/3] Fix regressions caused by registry series Simon Marchi via Gdb-patches

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=20220802201459.2839634-3-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@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