forked from Imagelibrary/binutils-gdb
Use gdb::unique_xmalloc_ptr when calling tilde_expand
This patch changes most sites calling tilde_expand to use gdb::unique_xmalloc_ptr, rather than a cleanup. It also changes scan_expression_with_cleanup to return a unique pointer, because the patch was already touching code in that area. Regression tested on the buildbot. ChangeLog 2017-08-05 Tom Tromey <tom@tromey.com> * compile/compile-object-load.c (compile_object_load): Use gdb::unique_xmalloc_ptr. * cli/cli-dump.c (scan_filename): Rename from scan_filename_with_cleanup. Change return type. (scan_expression): Rename from scan_expression_with_cleanup. Change return type. (dump_memory_to_file, dump_value_to_file, restore_command): Use gdb::unique_xmalloc_ptr. Update. * cli/cli-cmds.c (find_and_open_script): Use gdb::unique_xmalloc_ptr. * tracefile-tfile.c (tfile_open): Use gdb::unique_xmalloc_ptr. * symmisc.c (maintenance_print_symbols) (maintenance_print_msymbols): Use gdb::unique_xmalloc_ptr. * symfile.c (symfile_bfd_open, generic_load) (add_symbol_file_command, remove_symbol_file_command): Use gdb::unique_xmalloc_ptr. * source.c (openp): Use gdb::unique_xmalloc_ptr. * psymtab.c (maintenance_print_psymbols): Use gdb::unique_xmalloc_ptr. * corelow.c (core_open): Use gdb::unique_xmalloc_ptr. * breakpoint.c (save_breakpoints): Use gdb::unique_xmalloc_ptr. * solib.c (solib_map_sections): Use gdb::unique_xmalloc_ptr. (reload_shared_libraries_1): Likewise.
This commit is contained in:
@@ -277,7 +277,6 @@ core_open (const char *arg, int from_tty)
|
||||
char *temp;
|
||||
int scratch_chan;
|
||||
int flags;
|
||||
char *filename;
|
||||
|
||||
target_preopen (from_tty);
|
||||
if (!arg)
|
||||
@@ -289,31 +288,25 @@ core_open (const char *arg, int from_tty)
|
||||
error (_("No core file specified."));
|
||||
}
|
||||
|
||||
filename = tilde_expand (arg);
|
||||
if (!IS_ABSOLUTE_PATH (filename))
|
||||
{
|
||||
temp = concat (current_directory, "/",
|
||||
filename, (char *) NULL);
|
||||
xfree (filename);
|
||||
filename = temp;
|
||||
}
|
||||
|
||||
old_chain = make_cleanup (xfree, filename);
|
||||
gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
|
||||
if (!IS_ABSOLUTE_PATH (filename.get ()))
|
||||
filename.reset (concat (current_directory, "/",
|
||||
filename.get (), (char *) NULL));
|
||||
|
||||
flags = O_BINARY | O_LARGEFILE;
|
||||
if (write_files)
|
||||
flags |= O_RDWR;
|
||||
else
|
||||
flags |= O_RDONLY;
|
||||
scratch_chan = gdb_open_cloexec (filename, flags, 0);
|
||||
scratch_chan = gdb_open_cloexec (filename.get (), flags, 0);
|
||||
if (scratch_chan < 0)
|
||||
perror_with_name (filename);
|
||||
perror_with_name (filename.get ());
|
||||
|
||||
gdb_bfd_ref_ptr temp_bfd (gdb_bfd_fopen (filename, gnutarget,
|
||||
gdb_bfd_ref_ptr temp_bfd (gdb_bfd_fopen (filename.get (), gnutarget,
|
||||
write_files ? FOPEN_RUB : FOPEN_RB,
|
||||
scratch_chan));
|
||||
if (temp_bfd == NULL)
|
||||
perror_with_name (filename);
|
||||
perror_with_name (filename.get ());
|
||||
|
||||
if (!bfd_check_format (temp_bfd.get (), bfd_core)
|
||||
&& !gdb_check_format (temp_bfd.get ()))
|
||||
@@ -323,13 +316,12 @@ core_open (const char *arg, int from_tty)
|
||||
thing, on error it does not free all the storage associated
|
||||
with the bfd). */
|
||||
error (_("\"%s\" is not a core dump: %s"),
|
||||
filename, bfd_errmsg (bfd_get_error ()));
|
||||
filename.get (), bfd_errmsg (bfd_get_error ()));
|
||||
}
|
||||
|
||||
/* Looks semi-reasonable. Toss the old core file and work on the
|
||||
new. */
|
||||
|
||||
do_cleanups (old_chain);
|
||||
unpush_target (&core_ops);
|
||||
core_bfd = temp_bfd.release ();
|
||||
old_chain = make_cleanup (core_close_cleanup, 0 /*ignore*/);
|
||||
|
||||
Reference in New Issue
Block a user