From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 8106B38582A4; Wed, 3 Aug 2022 19:42:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8106B38582A4 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use auto_obstack in objfile X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 98badbfdc222d1d7f346046f23a64522b88d22a0 X-Git-Newrev: 075e4d6d95681bfbf53e849c2802a75d1d4cbdca Message-Id: <20220803194220.8106B38582A4@sourceware.org> Date: Wed, 3 Aug 2022 19:42:20 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Aug 2022 19:42:20 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D075e4d6d9568= 1bfbf53e849c2802a75d1d4cbdca commit 075e4d6d95681bfbf53e849c2802a75d1d4cbdca Author: Tom Tromey Date: Tue Aug 2 11:57:20 2022 -0600 Use auto_obstack in objfile =20 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 *na= me, objfile_flags flags_) { const char *expanded_name; =20 - /* 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 =3D=3D NULL) { @@ -583,9 +579,6 @@ objfile::~objfile () clear_current_source_symtab_and_line (); } =20 - /* 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 =3D 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. */ =20 - struct obstack objfile_obstack {}; + auto_obstack objfile_obstack; =20 /* Structure which keeps track of functions that manipulate objfile's of the same type as this objfile. I.e. the function to read partial