gdb/gdbsupport: make xstrprintf and xstrvprintf return a unique_ptr

The motivation is to reduce the number of places where unmanaged
pointers are returned from allocation type routines.  All of the
callers are updated.

There should be no user visible changes after this commit.
This commit is contained in:
Andrew Burgess 2021-11-08 14:58:46 +00:00
parent 2bb7589ddf
commit 8579fd136a
34 changed files with 119 additions and 151 deletions

View file

@ -234,7 +234,7 @@ SCM
gdbscm_make_type_error (const char *subr, int arg_pos, SCM bad_value,
const char *expected_type)
{
char *msg;
gdb::unique_xmalloc_ptr<char> msg;
SCM result;
if (arg_pos > 0)
@ -262,9 +262,8 @@ gdbscm_make_type_error (const char *subr, int arg_pos, SCM bad_value,
msg = xstrprintf (_("Wrong type argument: ~S"));
}
result = gdbscm_make_error (scm_arg_type_key, subr, msg,
result = gdbscm_make_error (scm_arg_type_key, subr, msg.get (),
scm_list_1 (bad_value), scm_list_1 (bad_value));
xfree (msg);
return result;
}
@ -279,7 +278,7 @@ static SCM
gdbscm_make_arg_error (SCM key, const char *subr, int arg_pos, SCM bad_value,
const char *error_prefix, const char *error)
{
char *msg;
gdb::unique_xmalloc_ptr<char> msg;
SCM result;
if (error_prefix != NULL)
@ -300,9 +299,8 @@ gdbscm_make_arg_error (SCM key, const char *subr, int arg_pos, SCM bad_value,
msg = xstrprintf (_("%s: ~S"), error);
}
result = gdbscm_make_error (key, subr, msg,
scm_list_1 (bad_value), scm_list_1 (bad_value));
xfree (msg);
result = gdbscm_make_error (key, subr, msg.get (), scm_list_1 (bad_value),
scm_list_1 (bad_value));
return result;
}