From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH] gdb: make inferior::terminal a unique ptr
Date: Thu, 25 Jun 2020 11:55:17 -0400 [thread overview]
Message-ID: <20200625155517.32173-1-simon.marchi@efficios.com> (raw)
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/infcmd.c | 6 ++----
gdb/inferior.c | 1 -
gdb/inferior.h | 3 ++-
3 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 42b050d3c4e..48d6a91c0c2 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -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
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 2f4ced0788d..d3bece029dd 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -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);
}
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 95af474eede..5002b0b8b3d 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -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 @@ class inferior : public refcounted_object
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. */
--
2.27.0
next reply other threads:[~2020-06-25 15:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 15:55 Simon Marchi [this message]
2020-06-25 17:18 ` Christian Biesinger
2020-06-25 17:28 ` Pedro Alves
2020-06-25 17:59 ` Luis Machado
2020-06-25 18:09 ` Pedro Alves
2020-06-25 18:39 ` Simon Marchi
2020-06-25 21:20 ` Christian Biesinger
2020-06-25 17:32 ` Pedro Alves
2020-06-25 18:42 ` Simon Marchi
2020-06-25 21:17 ` Pedro Alves
2020-06-25 20:15 ` Tom Tromey
2020-06-25 21:07 ` Simon Marchi
2020-06-25 21:45 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200625155517.32173-1-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox