aboutsummaryrefslogtreecommitdiff
path: root/gdb/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/exec.c')
-rw-r--r--gdb/exec.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/gdb/exec.c b/gdb/exec.c
index 3d26bcc..540c271 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