]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: make inferior::args a unique_xmalloc_ptr
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 6 May 2021 17:16:26 +0000 (13:16 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 6 May 2021 17:16:26 +0000 (13:16 -0400)
Use unique_xmalloc_ptr to avoid manual memory management.

gdb/ChangeLog:

* inferior.h (class inferior) <args>: Change type to
unique_xmalloc_ptr.
* inferior.c (inferior::~inferior): Don't free args.
* infcmd.c (get_inferior_args): Adjust.
(set_inferior_args): Adjust.

Change-Id: I96300e59eb2faf2d80660416a8f5694d243a944e

gdb/ChangeLog
gdb/infcmd.c
gdb/inferior.c
gdb/inferior.h

index 187249db47eab7aea643ab5f1df3e8418a883d23..6633ac548d3d3b26c3cf144a0180913715fab0b8 100644 (file)
@@ -1,3 +1,11 @@
+2021-05-06  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * inferior.h (class inferior) <args>: Change type to
+       unique_xmalloc_ptr.
+       * inferior.c (inferior::~inferior): Don't free args.
+       * infcmd.c (get_inferior_args): Adjust.
+       (set_inferior_args): Adjust.
+
 2021-05-06  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * guile/scm-breakpoint.c (bpscm_print_breakpoint_smob): Only print
index 5aa6b00f20f3da8681a0c736d2b7df85996d6c26..5d9d79261efe622a3786579141233459be6ed110 100644 (file)
@@ -136,9 +136,9 @@ get_inferior_args (void)
     }
 
   if (current_inferior ()->args == NULL)
-    current_inferior ()->args = xstrdup ("");
+    current_inferior ()->args = make_unique_xstrdup ("");
 
-  return current_inferior ()->args;
+  return current_inferior ()->args.get ();
 }
 
 /* Set the arguments for the current inferior.  Ownership of
@@ -147,8 +147,11 @@ get_inferior_args (void)
 void
 set_inferior_args (const char *newargs)
 {
-  xfree (current_inferior ()->args);
-  current_inferior ()->args = newargs ? xstrdup (newargs) : NULL;
+  if (newargs != nullptr)
+    current_inferior ()->args = make_unique_xstrdup (newargs);
+  else
+    current_inferior ()->args.reset ();
+
   current_inferior ()->argc = 0;
   current_inferior ()->argv = 0;
 }
index df3b7bf81f02d65a57f5853942bf57501bda6d28..a8779c354b5d4a76dc97bc8fcd1fbae2fd53c0b5 100644 (file)
@@ -75,7 +75,6 @@ inferior::~inferior ()
 
   m_continuations.clear ();
   inferior_free_data (inf);
-  xfree (inf->args);
   target_desc_info_free (inf->tdesc_info);
 }
 
index e0a7d622ccbb2d9323905bfa1612aeffc916e44a..4a143c3a2b8e8a9b2eafdf96f7231991ab07d77f 100644 (file)
@@ -468,7 +468,7 @@ public:
   struct program_space *pspace = NULL;
 
   /* The arguments string to use when running.  */
-  char *args = NULL;
+  gdb::unique_xmalloc_ptr<char> args;
 
   /* The size of elements in argv.  */
   int argc = 0;