[4/6] Use unique_xmalloc_ptr in bp_location

Message ID 20211005001453.2957929-5-tom@tromey.com
State New
Headers show
Series
  • Remove some uses of xfree
Related show

Commit Message

Tom Tromey Oct. 5, 2021, 12:14 a.m.
This changes struct bp_location to use a unique_xmalloc_ptr, removing
a bit of manual memory management.
---
 gdb/breakpoint.c | 12 ++++--------
 gdb/breakpoint.h |  4 ++--
 2 files changed, 6 insertions(+), 10 deletions(-)

-- 
2.31.1

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 477c03b7de3..5c3a6c6e4aa 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7192,7 +7192,7 @@  set_breakpoint_location_function (struct bp_location *loc)
 	find_pc_partial_function (loc->address, &function_name, NULL, NULL);
 
       if (function_name)
-	loc->function_name = xstrdup (function_name);
+	loc->function_name = make_unique_xstrdup (function_name);
     }
 }
 
@@ -12234,11 +12234,6 @@  say_where (struct breakpoint *b)
     }
 }
 
-bp_location::~bp_location ()
-{
-  xfree (function_name);
-}
-
 /* Destructor for the breakpoint base class.  */
 
 breakpoint::~breakpoint ()
@@ -13323,7 +13318,7 @@  ambiguous_names_p (struct bp_location *loc)
   for (l = loc; l != NULL; l = l->next)
     {
       const char **slot;
-      const char *name = l->function_name;
+      const char *name = l->function_name.get ();
 
       /* Allow for some names to be NULL, ignore them.  */
       if (name == NULL)
@@ -13642,7 +13637,8 @@  update_breakpoint_locations (struct breakpoint *b,
 	      {
 		for (bp_location *l : b->locations ())
 		  if (l->function_name
-		      && strcmp (e->function_name, l->function_name) == 0)
+		      && strcmp (e->function_name.get (),
+				 l->function_name.get ()) == 0)
 		    {
 		      l->enabled = e->enabled;
 		      l->disabled_by_cond = e->disabled_by_cond;
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index ad64f8320e9..304e2c1fca4 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -328,7 +328,7 @@  class bp_location : public refcounted_object
   /* Construct a bp_location with type TYPE.  */
   bp_location (breakpoint *owner, bp_loc_type type);
 
-  virtual ~bp_location ();
+  virtual ~bp_location () = default;
 
   /* Chain pointer to the next breakpoint location for
      the same parent breakpoint.  */
@@ -467,7 +467,7 @@  class bp_location : public refcounted_object
      with it.  */
   bound_probe probe {};
 
-  char *function_name = NULL;
+  gdb::unique_xmalloc_ptr<char> function_name;
 
   /* Details of the placed breakpoint, when inserted.  */
   bp_target_info target_info {};