From e3e41d588adbe26a6ca54338dd4915382d981a3e Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 3 Aug 2017 16:32:14 -0600 Subject: Change gdb_abspath to return a unique_xmalloc_ptr This changes gdb_abspath to return a unique_xmalloc_ptr, and fixes up the callers. This allows the removal of a cleanup, and also puts ownership rules into the API, where they belong. ChangeLog 2017-08-22 Tom Tromey * compile/compile.c (compile_file_command): Use gdb::unique_xmalloc_ptr, std::string. * utils.c (gdb_abspath): Change return type. * source.c (openp): Update. * objfiles.c (allocate_objfile): Update. * main.c (set_gdb_data_directory): Update. * utils.h (gdb_abspath): Return a gdb::unique_xmalloc_ptr. --- gdb/objfiles.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'gdb/objfiles.c') diff --git a/gdb/objfiles.c b/gdb/objfiles.c index d261c87..ff99ca6 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -386,22 +386,25 @@ allocate_objfile (bfd *abfd, const char *name, objfile_flags flags) objfile_alloc_data (objfile); + gdb::unique_xmalloc_ptr name_holder; if (name == NULL) { gdb_assert (abfd == NULL); gdb_assert ((flags & OBJF_NOT_FILENAME) != 0); - expanded_name = xstrdup ("<>"); + expanded_name = "<>"; } else if ((flags & OBJF_NOT_FILENAME) != 0 || is_target_filename (name)) - expanded_name = xstrdup (name); + expanded_name = name; else - expanded_name = gdb_abspath (name); + { + name_holder = gdb_abspath (name); + expanded_name = name_holder.get (); + } objfile->original_name = (char *) obstack_copy0 (&objfile->objfile_obstack, expanded_name, strlen (expanded_name)); - xfree (expanded_name); /* Update the per-objfile information that comes from the bfd, ensuring that any data that is reference is saved in the per-objfile data -- cgit v1.1