public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/6] Use unique_xmalloc_ptr in solib_catchpoint
Date: Mon,  4 Oct 2021 18:14:48 -0600	[thread overview]
Message-ID: <20211005001453.2957929-2-tom@tromey.com> (raw)
In-Reply-To: <20211005001453.2957929-1-tom@tromey.com>

This changes struct solib_catchpoint to use a unique_xmalloc_ptr,
removing a bit of manual memory management.
---
 gdb/breakpoint.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e742a1eccfe..7a9541836c9 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7973,22 +7973,15 @@ static struct breakpoint_ops catch_vfork_breakpoint_ops;
 
 struct solib_catchpoint : public breakpoint
 {
-  ~solib_catchpoint () override;
-
   /* True for "catch load", false for "catch unload".  */
   bool is_load;
 
   /* Regular expression to match, if any.  COMPILED is only valid when
      REGEX is non-NULL.  */
-  char *regex;
+  gdb::unique_xmalloc_ptr<char> regex;
   std::unique_ptr<compiled_regex> compiled;
 };
 
-solib_catchpoint::~solib_catchpoint ()
-{
-  xfree (this->regex);
-}
-
 static int
 insert_catch_solib (struct bp_location *ignore)
 {
@@ -8104,14 +8097,16 @@ print_one_catch_solib (struct breakpoint *b, struct bp_location **locs)
   if (self->is_load)
     {
       if (self->regex)
-	msg = string_printf (_("load of library matching %s"), self->regex);
+	msg = string_printf (_("load of library matching %s"),
+			     self->regex.get ());
       else
 	msg = _("load of library");
     }
   else
     {
       if (self->regex)
-	msg = string_printf (_("unload of library matching %s"), self->regex);
+	msg = string_printf (_("unload of library matching %s"),
+			     self->regex.get ());
       else
 	msg = _("unload of library");
     }
@@ -8139,7 +8134,7 @@ print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp)
 		      b->disposition == disp_del ? "tcatch" : "catch",
 		      self->is_load ? "load" : "unload");
   if (self->regex)
-    fprintf_unfiltered (fp, " %s", self->regex);
+    fprintf_unfiltered (fp, " %s", self->regex.get ());
   fprintf_unfiltered (fp, "\n");
 }
 
@@ -8162,7 +8157,7 @@ add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled)
     {
       c->compiled.reset (new compiled_regex (arg, REG_NOSUB,
 					     _("Invalid regexp")));
-      c->regex = xstrdup (arg);
+      c->regex = make_unique_xstrdup (arg);
     }
 
   c->is_load = is_load;
-- 
2.31.1


  reply	other threads:[~2021-10-05  0:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-05  0:14 [PATCH 0/6] Remove some uses of xfree Tom Tromey
2021-10-05  0:14 ` Tom Tromey [this message]
2021-10-05  0:14 ` [PATCH 2/6] Use unique_xmalloc_ptr in exec_catchpoint Tom Tromey
2021-10-05  0:14 ` [PATCH 3/6] Use unique_xmalloc_ptr in watchpoint Tom Tromey
2021-10-05  0:14 ` [PATCH 4/6] Use unique_xmalloc_ptr in bp_location Tom Tromey
2021-10-05  0:14 ` [PATCH 5/6] Use unique_xmalloc_ptr in breakpoing Tom Tromey
2021-10-05  0:14 ` [PATCH 6/6] Use std::string in print_one_catch_syscall Tom Tromey
2021-10-05 18:13 ` [PATCH 0/6] Remove some uses of xfree Bruno Larsen
2021-10-20 17:00 ` 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=20211005001453.2957929-2-tom@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).