public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/8] Use unique_ptr for trace_dirname
Date: Sun, 09 Jul 2023 11:01:50 -0600	[thread overview]
Message-ID: <20230709-trace-cleanups-v1-4-c410e1072fab@tromey.com> (raw)
In-Reply-To: <20230709-trace-cleanups-v1-0-c410e1072fab@tromey.com>

This changes trace_dirname to use unique_ptr, removing some manual
memory management.
---
 gdb/tracectf.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/gdb/tracectf.c b/gdb/tracectf.c
index 8f6ea250f61..fca623b3f21 100644
--- a/gdb/tracectf.c
+++ b/gdb/tracectf.c
@@ -862,7 +862,7 @@ static struct bt_ctf_iter *ctf_iter = NULL;
 static struct bt_iter_pos *start_pos;
 
 /* The name of CTF directory.  */
-static char *trace_dirname;
+static gdb::unique_xmalloc_ptr<char> trace_dirname;
 
 static ctf_target ctf_ops;
 
@@ -1164,7 +1164,7 @@ ctf_target_open (const char *dirname, int from_tty)
   start_pos = bt_iter_get_pos (bt_ctf_get_iter (ctf_iter));
   gdb_assert (start_pos->type == BT_SEEK_RESTORE);
 
-  trace_dirname = xstrdup (dirname);
+  trace_dirname = make_unique_xstrdup (dirname);
   current_inferior ()->push_target (&ctf_ops);
 
   inferior_appeared (current_inferior (), CTF_PID);
@@ -1185,8 +1185,7 @@ void
 ctf_target::close ()
 {
   ctf_destroy ();
-  xfree (trace_dirname);
-  trace_dirname = NULL;
+  trace_dirname.reset ();
 
   switch_to_no_thread ();	/* Avoid confusion from thread stuff.  */
   exit_inferior_silent (current_inferior ());
@@ -1200,7 +1199,7 @@ ctf_target::close ()
 void
 ctf_target::files_info ()
 {
-  gdb_printf ("\t`%s'\n", trace_dirname);
+  gdb_printf ("\t`%s'\n", trace_dirname.get ());
 }
 
 /* This is the implementation of target_ops method to_fetch_registers.

-- 
2.41.0


  parent reply	other threads:[~2023-07-09 17:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09 17:01 [PATCH 0/8] Minor C++-ification and cleanup in trace targets Tom Tromey
2023-07-09 17:01 ` [PATCH 1/8] Remove a use of xfree Tom Tromey
2023-07-09 17:01 ` [PATCH 2/8] Replace use of xfree with byte_vector Tom Tromey
2023-07-09 17:01 ` [PATCH 3/8] Use unique_ptr for trace_filename Tom Tromey
2023-07-09 17:01 ` Tom Tromey [this message]
2023-07-09 17:01 ` [PATCH 5/8] Use function_view in traceframe_walk_blocks Tom Tromey
2023-07-09 17:01 ` [PATCH 6/8] Constify tfile_interp_line Tom Tromey
2023-07-09 17:01 ` [PATCH 7/8] Move definition of ctf_target type Tom Tromey
2023-07-09 17:01 ` [PATCH 8/8] Change 'handle_id' to be a local variable Tom Tromey
2023-07-09 20:52 ` [PATCH 0/8] Minor C++-ification and cleanup in trace targets Keith Seitz
2023-07-10 19:02   ` 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=20230709-trace-cleanups-v1-4-c410e1072fab@tromey.com \
    --to=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).