This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Use unique_xmalloc_ptr in cd_command


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6eecf35f97e1d37e49e385ba599797dd1c8afd1f

commit 6eecf35f97e1d37e49e385ba599797dd1c8afd1f
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Aug 13 14:34:59 2017 -0600

    Use unique_xmalloc_ptr in cd_command
    
    Change cd_command to use unique_xmalloc_ptr, removing a cleanup.
    
    ChangeLog
    2017-09-03  Tom Tromey  <tom@tromey.com>
    
    	* cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr.

Diff:
---
 gdb/ChangeLog      |  4 ++++
 gdb/cli/cli-cmds.c | 20 +++++++++-----------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8d75d48..6d6dad1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2017-09-03  Tom Tromey  <tom@tromey.com>
 
+	* cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr.
+
+2017-09-03  Tom Tromey  <tom@tromey.com>
+
 	* mi/mi-interp.c (mi_cmd_interpreter_exec): Use std::string.
 
 2017-09-03  Tom Tromey  <tom@tromey.com>
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index d4dc539..8221747 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -398,14 +398,14 @@ cd_command (char *dir, int from_tty)
   /* Found something other than leading repetitions of "/..".  */
   int found_real_path;
   char *p;
-  struct cleanup *cleanup;
 
   /* If the new directory is absolute, repeat is a no-op; if relative,
      repeat might be useful but is more likely to be a mistake.  */
   dont_repeat ();
 
-  dir = tilde_expand (dir != NULL ? dir : "~");
-  cleanup = make_cleanup (xfree, dir);
+  gdb::unique_xmalloc_ptr<char> dir_holder
+    (tilde_expand (dir != NULL ? dir : "~"));
+  dir = dir_holder.get ();
 
   if (chdir (dir) < 0)
     perror_with_name (dir);
@@ -430,17 +430,17 @@ cd_command (char *dir, int from_tty)
 	len--;
     }
 
-  dir = savestring (dir, len);
-  if (IS_ABSOLUTE_PATH (dir))
-    current_directory = dir;
+  dir_holder.reset (savestring (dir, len));
+  if (IS_ABSOLUTE_PATH (dir_holder.get ()))
+    current_directory = dir_holder.release ();
   else
     {
       if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]))
-	current_directory = concat (current_directory, dir, (char *)NULL);
+	current_directory = concat (current_directory, dir_holder.get (),
+				    (char *) NULL);
       else
 	current_directory = concat (current_directory, SLASH_STRING,
-				    dir, (char *)NULL);
-      xfree (dir);
+				    dir_holder.get (), (char *) NULL);
     }
 
   /* Now simplify any occurrences of `.' and `..' in the pathname.  */
@@ -489,8 +489,6 @@ cd_command (char *dir, int from_tty)
 
   if (from_tty)
     pwd_command ((char *) 0, 1);
-
-  do_cleanups (cleanup);
 }
 
 /* Show the current value of the 'script-extension' option.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]