From a4453b7e0b9b84dd18c844ef43fbb9f6e2e75433 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 18 Jul 2012 19:34:57 +0000 Subject: * symfile.c (symfile_bfd_open): Don't copy name. Call gdb_bfd_stash_filename. (load_command): Open the new BFD before freeing the old. (bfd_open_maybe_remote): Call gdb_bfd_stash_filename. * symfile-mem.c (symbol_file_add_from_memory): Don't copy name. Call gdb_bfd_stash_filename. * spu-linux-nat.c (spu_bfd_open): Don't copy name. * solib-spu.c (spu_bfd_fopen): Don't copy name. Call gdb_bfd_stash_filename. * solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init): Free found_pathname. * rs6000-nat.c (add_vmap): Don't copy filename. Call gdb_bfd_stash_filename. * remote.c (remote_bfd_open): Call gdb_bfd_stash_filename. * machoread.c (macho_add_oso_symfile): Call gdb_bfd_stash_filename. (macho_symfile_read_all_oso): Arrange to free archive_name. Call gdb_bfd_stash_filename. (macho_check_dsym): Don't copy filename. Call gdb_bfd_stash_filename. * jit.c (bfd_open_from_target_memory): Don't copy the filename. * gdb_bfd.c (gdb_bfd_stash_filename): New function. * gdb_bfd.h (gdb_bfd_stash_filename): Declare. * gcore.c (create_gcore_bfd): Call gdb_bfd_stash_filename. * exec.c (exec_close): Don't free the BFD's filename. (exec_file_attach): Don't copy the filename. Call gdb_bfd_stash_filename. * corelow.c (core_close): Don't free the BFD's filename. (core_open): Call gdb_bfd_stash_filename. * corefile.c (reopen_exec_file): Remove #if 0 code. * solib.c (solib_bfd_fopen): Call gdb_bfd_stash_filename. Free pathname. * dwarf2read.c (try_open_dwo_file): Call gdb_bfd_stash_filename. --- gdb/exec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'gdb/exec.c') diff --git a/gdb/exec.c b/gdb/exec.c index 3d26bcc3f48..540c27132b8 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -99,10 +99,8 @@ exec_close (void) if (exec_bfd) { bfd *abfd = exec_bfd; - char *name = bfd_get_filename (abfd); gdb_bfd_unref (abfd); - xfree (name); /* Removing target sections may close the exec_ops target. Clear exec_bfd before doing so to prevent recursion. */ @@ -230,6 +228,9 @@ exec_file_attach (char *filename, int from_tty) &scratch_pathname); } #endif + + cleanups = make_cleanup (xfree, scratch_pathname); + if (scratch_chan < 0) perror_with_name (filename); exec_bfd = gdb_bfd_ref (bfd_fopen (scratch_pathname, gnutarget, @@ -242,13 +243,6 @@ exec_file_attach (char *filename, int from_tty) scratch_pathname, bfd_errmsg (bfd_get_error ())); } - /* At this point, scratch_pathname and exec_bfd->name both point to the - same malloc'd string. However exec_close() will attempt to free it - via the exec_bfd->name pointer, so we need to make another copy and - leave exec_bfd as the new owner of the original copy. */ - scratch_pathname = xstrdup (scratch_pathname); - cleanups = make_cleanup (xfree, scratch_pathname); - if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching)) { /* Make sure to close exec_bfd, or else "run" might try to use @@ -259,6 +253,8 @@ exec_file_attach (char *filename, int from_tty) gdb_bfd_errmsg (bfd_get_error (), matching)); } + gdb_bfd_stash_filename (exec_bfd); + /* FIXME - This should only be run for RS6000, but the ifdef is a poor way to accomplish. */ #ifdef DEPRECATED_IBM6000_TARGET -- cgit v1.2.3