aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-05-06 13:16:26 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-06 13:16:26 -0400
commitec66d6ea54679d00c1f0d52a5a9fa0cbb8b86d47 (patch)
treeac7be1cbde883fe323f0c1962c5f2a7971203f5f
parent482155e6090a602cd31112d1e3f4e80d37fe6189 (diff)
downloadgdb-ec66d6ea54679d00c1f0d52a5a9fa0cbb8b86d47.zip
gdb-ec66d6ea54679d00c1f0d52a5a9fa0cbb8b86d47.tar.gz
gdb-ec66d6ea54679d00c1f0d52a5a9fa0cbb8b86d47.tar.bz2
gdb: make inferior::args a unique_xmalloc_ptr
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
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/infcmd.c11
-rw-r--r--gdb/inferior.c1
-rw-r--r--gdb/inferior.h2
4 files changed, 16 insertions, 6 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 187249d..6633ac5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 5aa6b00..5d9d792 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -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;
}
diff --git a/gdb/inferior.c b/gdb/inferior.c
index df3b7bf..a8779c3 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -75,7 +75,6 @@ inferior::~inferior ()
m_continuations.clear ();
inferior_free_data (inf);
- xfree (inf->args);
target_desc_info_free (inf->tdesc_info);
}
diff --git a/gdb/inferior.h b/gdb/inferior.h
index e0a7d62..4a143c3 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -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;