Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 1/2] Fix erroneous cleanup use in add_solib_catchpoint
Date: Sun, 20 Aug 2017 14:06:00 -0000	[thread overview]
Message-ID: <20170820135402.1213-2-tom@tromey.com> (raw)
In-Reply-To: <20170820135402.1213-1-tom@tromey.com>

I happened to notice that add_solib_catchpoint allocated the new
catchpoint with "new" but installed a cleanup using "xfree".  This
patch fixes the bug by changing the function to use std::unique_ptr
instead.

gdb/ChangeLog
2017-08-19  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (add_solib_catchpoint): Use std::unique_ptr.
---
 gdb/ChangeLog    |  4 ++++
 gdb/breakpoint.c | 10 +++-------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7ad3f4c..339ab3a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-19  Tom Tromey  <tom@tromey.com>
+
+	* breakpoint.c (add_solib_catchpoint): Use std::unique_ptr.
+
 2017-08-18  Tom Tromey  <tom@tromey.com>
 	    Pedro Alves  <palves@redhat.com>
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index bc681cf..135741a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8464,16 +8464,13 @@ static struct breakpoint_ops catch_solib_breakpoint_ops;
 void
 add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
 {
-  struct solib_catchpoint *c;
   struct gdbarch *gdbarch = get_current_arch ();
-  struct cleanup *cleanup;
 
   if (!arg)
     arg = "";
   arg = skip_spaces_const (arg);
 
-  c = new solib_catchpoint ();
-  cleanup = make_cleanup (xfree, c);
+  std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
 
   if (*arg != '\0')
     {
@@ -8483,13 +8480,12 @@ add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
     }
 
   c->is_load = is_load;
-  init_catchpoint (c, gdbarch, is_temp, NULL,
+  init_catchpoint (c.get (), gdbarch, is_temp, NULL,
 		   &catch_solib_breakpoint_ops);
 
   c->enable_state = enabled ? bp_enabled : bp_disabled;
 
-  discard_cleanups (cleanup);
-  install_breakpoint (0, c, 1);
+  install_breakpoint (0, c.release (), 1);
 }
 
 /* A helper function that does all the work for "catch load" and
-- 
2.9.4


      parent reply	other threads:[~2017-08-20 14:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-20 13:54 [RFA 0/2] small clean ups in breakpoint allocation Tom Tromey
2017-08-20 14:06 ` [RFA 2/2] Change install_breakpoint to take a std::unique_ptr Tom Tromey
2017-08-21 10:12   ` Pedro Alves
2017-08-22  3:55     ` Tom Tromey
2017-08-22  8:56       ` Pedro Alves
2017-08-20 14:06 ` Tom Tromey [this message]

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=20170820135402.1213-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