From e0cc99a62f9ceb9a0db0b5bc28711fd8c82a6151 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 10 Nov 2017 13:47:05 -0700 Subject: Change openp et al to use a unique_xmalloc_ptr This changes openp, source_full_path_of, and find_and_open_source to take a unique_xmalloc_ptr, rather than a char*, as an outgoing argument type. This simplifies the API, ownership-wise, and allows for the removal of some cleanups. gdb/ChangeLog 2018-02-14 Tom Tromey * symfile.c (symfile_bfd_open): Update. * source.h (openp, source_full_path_of, find_and_open_source): Change argument type to unique_xmalloc_ptr. * source.c (openp): Take a unique_xmalloc_ptr. (source_full_path_of, find_and_open_source): Likewise. (open_source_file, symtab_to_fullname): Update. * solist.h (struct target_so_ops) : Take a unique_xmalloc_ptr. * solib.c (solib_find_1): Use unique_xmalloc_ptr. (exec_file_find): Update. * psymtab.c (psymtab_to_fullname): Update. * nto-tdep.h (nto_find_and_open_solib): Update. * nto-tdep.c (nto_find_and_open_solib): Change temp_path to a unique_xmalloc_ptr. * exec.c (exec_file_attach): Update. * dwarf2read.c (try_open_dwop_file): Use unique_xmalloc_ptr. * cli/cli-cmds.c (find_and_open_script): Use unique_xmalloc_ptr. --- gdb/symfile.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'gdb/symfile.c') diff --git a/gdb/symfile.c b/gdb/symfile.c index ab6ec1c..699d9e6 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1719,12 +1719,10 @@ gdb_bfd_ref_ptr symfile_bfd_open (const char *name) { int desc = -1; - struct cleanup *back_to = make_cleanup (null_cleanup, 0); + gdb::unique_xmalloc_ptr absolute_name; if (!is_target_filename (name)) { - char *absolute_name; - gdb::unique_xmalloc_ptr expanded_name (tilde_expand (name)); /* Look down path for it, allocate 2nd new malloc'd copy. */ @@ -1745,8 +1743,7 @@ symfile_bfd_open (const char *name) if (desc < 0) perror_with_name (expanded_name.get ()); - make_cleanup (xfree, absolute_name); - name = absolute_name; + name = absolute_name.get (); } gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (name, gnutarget, desc)); @@ -1761,8 +1758,6 @@ symfile_bfd_open (const char *name) error (_("`%s': can't read symbols: %s."), name, bfd_errmsg (bfd_get_error ())); - do_cleanups (back_to); - return sym_bfd; } -- cgit v1.1