gdb: make inferior::terminal a unique ptr
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 25 Jun 2020 18:44:13 +0000 (14:44 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 25 Jun 2020 18:44:35 +0000 (14:44 -0400)
This changes the inferior::terminal field to be a unique pointer, so its
deallocation is automatically managed.

gdb/ChangeLog:

* inferior.h (struct inferior) <terminal>: Change type to
gdb::unique_xmalloc_ptr<char>.
* inferior.c (inferior::~inferior): Don't free inf->terminal.
* infcmd.c (set_inferior_io_terminal): Don't free terminal
field, adjust to unique pointer.
(get_inferior_io_terminal): Adjust to unique pointer.

Change-Id: Iedb6459b4f9eeae812b0cb9d514b5707d5107cdb

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

index 0a36c6bc48c85df2e4a4311bcd0f124416e2e8ee..d9b6a49bd1057425a9808c0efec72c792b7fea11 100644 (file)
@@ -1,3 +1,12 @@
+2020-06-25  Simon Marchi  <simon.marchi@efficios.com>
+
+       * inferior.h (struct inferior) <terminal>: Change type to
+       gdb::unique_xmalloc_ptr<char>.
+       * inferior.c (inferior::~inferior): Don't free inf->terminal.
+       * infcmd.c (set_inferior_io_terminal): Don't free terminal
+       field, adjust to unique pointer.
+       (get_inferior_io_terminal): Adjust to unique pointer.
+
 2020-06-25  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * riscv-tdep.c (riscv_print_registers_info): Loop over all
index 42b050d3c4e94836a9014b36fa84e3c5808ff5ef..48d6a91c0c2499ae7fcd4c0aef8f02d6c4da6d34 100644 (file)
@@ -108,10 +108,8 @@ int stopped_by_random_signal;
 void 
 set_inferior_io_terminal (const char *terminal_name)
 {
-  xfree (current_inferior ()->terminal);
-
   if (terminal_name != NULL && *terminal_name != '\0')
-    current_inferior ()->terminal = xstrdup (terminal_name);
+    current_inferior ()->terminal.reset (xstrdup (terminal_name));
   else
     current_inferior ()->terminal = NULL;
 }
@@ -119,7 +117,7 @@ set_inferior_io_terminal (const char *terminal_name)
 const char *
 get_inferior_io_terminal (void)
 {
-  return current_inferior ()->terminal;
+  return current_inferior ()->terminal.get ();
 }
 
 static void
index 2f4ced0788d5cb32260bf51c8112925401c128f0..d3bece029dd4a7152088c591937f9d050bed57eb 100644 (file)
@@ -79,7 +79,6 @@ inferior::~inferior ()
   discard_all_inferior_continuations (inf);
   inferior_free_data (inf);
   xfree (inf->args);
-  xfree (inf->terminal);
   target_desc_info_free (inf->tdesc_info);
 }
 
index 95af474eedeb77a025565c1f43bb7dd25f929759..5002b0b8b3d31d370038e1a01b4e4bc07de9eeb6 100644 (file)
@@ -52,6 +52,7 @@ struct thread_info;
 #include "symfile-add-flags.h"
 #include "gdbsupport/refcounted-object.h"
 #include "gdbsupport/forward-scope-exit.h"
+#include "gdbsupport/gdb_unique_ptr.h"
 
 #include "gdbsupport/common-inferior.h"
 #include "gdbthread.h"
@@ -456,7 +457,7 @@ public:
   gdb::unique_xmalloc_ptr<char> cwd;
 
   /* The name of terminal device to use for I/O.  */
-  char *terminal = NULL;
+  gdb::unique_xmalloc_ptr<char> terminal;
 
   /* The terminal state as set by the last target_terminal::terminal_*
      call.  */
This page took 0.047507 seconds and 4 git commands to generate.