From 98badbfdc222d1d7f346046f23a64522b88d22a0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 2 Aug 2022 09:55:32 -0600 Subject: Use gdb_bfd_ref_ptr in objfile This changes struct objfile to use a gdb_bfd_ref_ptr. In addition to removing some manual memory management, this fixes a use-after-free that was introduced by the registry rewrite series. The issue there was that, in some cases, registry shutdown could refer to memory that had already been freed. This help fix the bug by delaying the destruction of the BFD reference (and thus the per-bfd object) until after the registry has been shut down. --- gdb/symfile-mem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gdb/symfile-mem.c') diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index 73c5ee3..78c0e09 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -119,7 +119,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, if (from_tty) add_flags |= SYMFILE_VERBOSE; - objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd), + objf = symbol_file_add_from_bfd (nbfd_holder, bfd_get_filename (nbfd), add_flags, &sai, OBJF_SHARED, NULL); current_program_space->add_target_sections (objf); @@ -144,7 +144,7 @@ add_symbol_file_from_memory_command (const char *args, int from_tty) /* We need some representative bfd to know the target we are looking at. */ if (current_program_space->symfile_object_file != NULL) - templ = current_program_space->symfile_object_file->obfd; + templ = current_program_space->symfile_object_file->obfd.get (); else templ = current_program_space->exec_bfd (); if (templ == NULL) -- cgit v1.1