public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Use auto_obstack in objfile
@ 2022-08-03 19:42 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-08-03 19:42 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=075e4d6d95681bfbf53e849c2802a75d1d4cbdca

commit 075e4d6d95681bfbf53e849c2802a75d1d4cbdca
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Aug 2 11:57:20 2022 -0600

    Use auto_obstack in objfile
    
    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.

Diff:
---
 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 @@ public:
   /* 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-03 19:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03 19:42 [binutils-gdb] Use auto_obstack in objfile Tom Tromey

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