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/utils.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'gdb/utils.c') diff --git a/gdb/utils.c b/gdb/utils.c index 96ae709..9959c01 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2761,28 +2761,25 @@ gdb_realpath_keepfile (const char *filename) /* Return PATH in absolute form, performing tilde-expansion if necessary. PATH cannot be NULL or the empty string. - This does not resolve symlinks however, use gdb_realpath for that. - Space for the result is allocated with malloc. - If the path is already absolute, it is strdup'd. - If there is a problem computing the absolute path, the path is returned - unchanged (still strdup'd). */ + This does not resolve symlinks however, use gdb_realpath for that. */ -char * +gdb::unique_xmalloc_ptr gdb_abspath (const char *path) { gdb_assert (path != NULL && path[0] != '\0'); if (path[0] == '~') - return tilde_expand (path); + return gdb::unique_xmalloc_ptr (tilde_expand (path)); if (IS_ABSOLUTE_PATH (path)) - return xstrdup (path); + return gdb::unique_xmalloc_ptr (xstrdup (path)); /* Beware the // my son, the Emacs barfs, the botch that catch... */ - return concat (current_directory, - IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) - ? "" : SLASH_STRING, - path, (char *) NULL); + return gdb::unique_xmalloc_ptr + (concat (current_directory, + IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) + ? "" : SLASH_STRING, + path, (char *) NULL)); } ULONGEST -- cgit v1.1