]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use auto_obstack in objfile
authorTom Tromey <tom@tromey.com>
Tue, 2 Aug 2022 17:57:20 +0000 (11:57 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 3 Aug 2022 19:26:58 +0000 (13:26 -0600)
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
gdb/objfiles.h

index 3db9135a64be76f4f9dcba7ff99267d13aa8d27d..c92da7548b3274a6e2f6e38150fccb858a89a23f 100644 (file)
@@ -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;
 }
index eb85ed478c64743561b72ced2ce103169e061600..ac45fa3980f2d272d9e4f5b4503be343c1885c88 100644 (file)
@@ -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