aboutsummaryrefslogtreecommitdiff
path: root/gdb/location.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-01-14 07:24:18 -0700
committerTom Tromey <tom@tromey.com>2022-01-18 10:00:00 -0700
commitdab863ef408588aba1c396901e3e5070948d2047 (patch)
tree9ce96ef1d6d47d125ba54fd3d235f4d41d2eb281 /gdb/location.c
parente53c95d40b128a1e794b27ec8b166ae1445356eb (diff)
downloadgdb-dab863ef408588aba1c396901e3e5070948d2047.zip
gdb-dab863ef408588aba1c396901e3e5070948d2047.tar.gz
gdb-dab863ef408588aba1c396901e3e5070948d2047.tar.bz2
Remove a use of xfree in location.c
This small cleanup removes a use of xfree from location.c, by switching to unique_xmalloc_ptr. One function is only used in location.c, so it is made static. And, another function is changed to avoid a copy.
Diffstat (limited to 'gdb/location.c')
-rw-r--r--gdb/location.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/gdb/location.c b/gdb/location.c
index 45f1d59..d4180cf 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -231,7 +231,7 @@ get_explicit_location_const (const struct event_location *location)
AS_LINESPEC is non-zero if this string should be a linespec.
Otherwise it will be output in explicit form. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
explicit_to_string_internal (int as_linespec,
const struct explicit_location *explicit_loc)
{
@@ -282,12 +282,12 @@ explicit_to_string_internal (int as_linespec,
explicit_loc->line_offset.offset);
}
- return xstrdup (buf.c_str ());
+ return make_unique_xstrdup (buf.c_str ());
}
/* See description in location.h. */
-char *
+static gdb::unique_xmalloc_ptr<char>
explicit_location_to_string (const struct explicit_location *explicit_loc)
{
return explicit_to_string_internal (0, explicit_loc);
@@ -295,7 +295,7 @@ explicit_location_to_string (const struct explicit_location *explicit_loc)
/* See description in location.h. */
-char *
+gdb::unique_xmalloc_ptr<char>
explicit_location_to_linespec (const struct explicit_location *explicit_loc)
{
return explicit_to_string_internal (1, explicit_loc);
@@ -425,7 +425,7 @@ event_location_to_string (struct event_location *location)
case EXPLICIT_LOCATION:
EL_STRING (location)
- = explicit_location_to_string (EL_EXPLICIT (location));
+ = explicit_location_to_string (EL_EXPLICIT (location)).release ();
break;
case PROBE_LOCATION:
@@ -981,8 +981,8 @@ event_location_empty_p (const struct event_location *location)
void
set_event_location_string (struct event_location *location,
- const char *string)
+ gdb::unique_xmalloc_ptr<char> string)
{
xfree (EL_STRING (location));
- EL_STRING (location) = string == NULL ? NULL : xstrdup (string);
+ EL_STRING (location) = string.release ();
}