From: Tom Tromey Date: Fri, 14 Jan 2022 14:24:18 +0000 (-0700) Subject: Remove a use of xfree in location.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dab863ef408588aba1c396901e3e5070948d2047;p=binutils-gdb.git 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. --- diff --git a/gdb/linespec.c b/gdb/linespec.c index eb911ccdb35..b24cf30dc71 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -2098,12 +2098,8 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls) /* If this location originally came from a linespec, save a string representation of it for display and saving to file. */ if (state->is_linespec) - { - char *linespec = explicit_location_to_linespec (explicit_loc); - - set_event_location_string (canon, linespec); - xfree (linespec); - } + set_event_location_string (canon, + explicit_location_to_linespec (explicit_loc)); } /* Given a line offset in LS, construct the relevant SALs. */ diff --git a/gdb/location.c b/gdb/location.c index 45f1d59ad81..d4180cfe429 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 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 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 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 string) { xfree (EL_STRING (location)); - EL_STRING (location) = string == NULL ? NULL : xstrdup (string); + EL_STRING (location) = string.release (); } diff --git a/gdb/location.h b/gdb/location.h index c6e1402d762..b391ce3b1dd 100644 --- a/gdb/location.h +++ b/gdb/location.h @@ -109,16 +109,10 @@ struct explicit_location extern enum event_location_type event_location_type (const struct event_location *); -/* Return a malloc'd explicit string representation of the given - explicit location. The location must already be canonicalized/valid. */ +/* Return a linespec string representation of the given explicit + location. The location must already be canonicalized/valid. */ -extern char * - explicit_location_to_string (const struct explicit_location *explicit_loc); - -/* Return a malloc'd linespec string representation of the given - explicit location. The location must already be canonicalized/valid. */ - -extern char * +extern gdb::unique_xmalloc_ptr explicit_location_to_linespec (const struct explicit_location *explicit_loc); /* Return a string representation of the LOCATION. @@ -286,6 +280,6 @@ extern int event_location_empty_p (const struct event_location *location); extern void set_event_location_string (struct event_location *location, - const char *string); + gdb::unique_xmalloc_ptr string); #endif /* LOCATION_H */