Use gdb::unique_xmalloc_ptr when calling tilde_expand
[deliverable/binutils-gdb.git] / gdb / cli / cli-cmds.c
index 036a2f0c03d51b8953167180646d2ef83f05840d..d3ec4aeaa3c0a56d7388c0e7d49b72393feca0ff 100644 (file)
@@ -516,14 +516,11 @@ show_script_ext_mode (struct ui_file *file, int from_tty,
 gdb::optional<open_script>
 find_and_open_script (const char *script_file, int search_path)
 {
-  char *file;
   int fd;
-  struct cleanup *old_cleanups;
   int search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH;
   gdb::optional<open_script> opened;
 
-  file = tilde_expand (script_file);
-  old_cleanups = make_cleanup (xfree, file);
+  gdb::unique_xmalloc_ptr<char> file (tilde_expand (script_file));
 
   if (search_path)
     search_flags |= OPF_SEARCH_IN_PATH;
@@ -532,18 +529,11 @@ find_and_open_script (const char *script_file, int search_path)
      files.  Put the full location in *FULL_PATHP.  */
   char *temp_path;
   fd = openp (source_path, search_flags,
-             file, O_RDONLY, &temp_path);
+             file.get (), O_RDONLY, &temp_path);
   gdb::unique_xmalloc_ptr<char> full_path (temp_path);
 
   if (fd == -1)
-    {
-      int save_errno = errno;
-      do_cleanups (old_cleanups);
-      errno = save_errno;
-      return opened;
-    }
-
-  do_cleanups (old_cleanups);
+    return opened;
 
   FILE *result = fdopen (fd, FOPEN_RT);
   if (result == NULL)
This page took 0.027277 seconds and 4 git commands to generate.