From ee0c32930c355b73172b2bef987e2a48ea909b12 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 31 Jul 2017 15:49:21 -0600 Subject: 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 * 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. --- gdb/tracefile-tfile.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'gdb/tracefile-tfile.c') diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index fb4283f..37bd96a 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -423,7 +423,6 @@ static void tfile_open (const char *arg, int from_tty) { char *temp; - struct cleanup *old_chain; int flags; int scratch_chan; char header[TRACE_HEADER_SIZE]; @@ -433,34 +432,27 @@ tfile_open (const char *arg, int from_tty) struct trace_status *ts; struct uploaded_tp *uploaded_tps = NULL; struct uploaded_tsv *uploaded_tsvs = NULL; - char *filename; target_preopen (from_tty); if (!arg) error (_("No trace 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 filename (tilde_expand (arg)); + if (!IS_ABSOLUTE_PATH (filename.get ())) + filename.reset (concat (current_directory, "/", filename.get (), + (char *) NULL)); flags = O_BINARY | O_LARGEFILE; 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 ()); /* Looks semi-reasonable. Toss the old trace file and work on the new. */ - discard_cleanups (old_chain); /* Don't free filename any more. */ unpush_target (&tfile_ops); - trace_filename = xstrdup (filename); + trace_filename = filename.release (); trace_fd = scratch_chan; /* Make sure this is clear. */ -- cgit v1.1