From 5c1146d2dec3d6f2ca56456f215084b910938b92 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 2 Oct 2021 16:43:49 -0600 Subject: Use unique_xmalloc_ptr in exec_catchpoint This changes struct exec_catchpoint to use a unique_xmalloc_ptr, removing a bit of manual memory management. --- gdb/breakpoint.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 7a9541836c9..8016dd3b83f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -8250,21 +8250,12 @@ create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, struct exec_catchpoint : public breakpoint { - ~exec_catchpoint () override; - /* Filename of a program whose exec triggered this catchpoint. This field is only valid immediately after this catchpoint has triggered. */ - char *exec_pathname; + gdb::unique_xmalloc_ptr exec_pathname; }; -/* Exec catchpoint destructor. */ - -exec_catchpoint::~exec_catchpoint () -{ - xfree (this->exec_pathname); -} - static int insert_catch_exec (struct bp_location *bl) { @@ -8287,7 +8278,7 @@ breakpoint_hit_catch_exec (const struct bp_location *bl, if (ws->kind != TARGET_WAITKIND_EXECD) return 0; - c->exec_pathname = xstrdup (ws->value.execd_pathname); + c->exec_pathname = make_unique_xstrdup (ws->value.execd_pathname); return 1; } @@ -8311,7 +8302,7 @@ print_it_catch_exec (bpstat bs) } uiout->field_signed ("bkptno", b->number); uiout->text (" (exec'd "); - uiout->field_string ("new-exec", c->exec_pathname); + uiout->field_string ("new-exec", c->exec_pathname.get ()); uiout->text ("), "); return PRINT_SRC_AND_LOC; @@ -8336,7 +8327,7 @@ print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) if (c->exec_pathname != NULL) { uiout->text (", program \""); - uiout->field_string ("what", c->exec_pathname); + uiout->field_string ("what", c->exec_pathname.get ()); uiout->text ("\" "); } @@ -11324,7 +11315,7 @@ catch_exec_command_1 (const char *arg, int from_tty, std::unique_ptr c (new exec_catchpoint ()); init_catchpoint (c.get (), gdbarch, temp, cond_string, &catch_exec_breakpoint_ops); - c->exec_pathname = NULL; + c->exec_pathname.reset (); install_breakpoint (0, std::move (c), 1); } -- cgit v1.2.1