mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-30 12:44:10 +08:00
Return unique_xmalloc_ptr from gdbscm_safe_eval_string
This changes gdbscm_safe_eval_string to return a unique_xmalloc_ptr. This allows for the removal of some cleanups. It also fixes a potential latent memory leak in gdbscm_set_backtrace. gdb/ChangeLog 2018-07-17 Tom Tromey <tom@tromey.com> * guile/guile.c (gdbscm_eval_from_control_command): Update. * guile/guile-internal.h (gdbscm_safe_eval_string): Update. * guile/scm-objfile.c (gdbscm_execute_objfile_script): Update. * guile/scm-safe-call.c (gdbscm_safe_eval_string): Return unique_xmalloc_ptr.
This commit is contained in:
parent
15bf30027b
commit
a1a31cb8dc
@ -1,3 +1,11 @@
|
||||
2018-07-17 Tom Tromey <tom@tromey.com>
|
||||
|
||||
* guile/guile.c (gdbscm_eval_from_control_command): Update.
|
||||
* guile/guile-internal.h (gdbscm_safe_eval_string): Update.
|
||||
* guile/scm-objfile.c (gdbscm_execute_objfile_script): Update.
|
||||
* guile/scm-safe-call.c (gdbscm_safe_eval_string): Return
|
||||
unique_xmalloc_ptr.
|
||||
|
||||
2018-07-17 Tom Tromey <tom@tromey.com>
|
||||
|
||||
* guile/scm-param.c (pascm_signal_setshow_error): Update.
|
||||
|
@ -402,7 +402,8 @@ extern SCM gdbscm_safe_apply_1 (SCM proc, SCM arg0, SCM args,
|
||||
|
||||
extern SCM gdbscm_unsafe_call_1 (SCM proc, SCM arg0);
|
||||
|
||||
extern char *gdbscm_safe_eval_string (const char *string, int display_result);
|
||||
extern gdb::unique_xmalloc_ptr<char> gdbscm_safe_eval_string
|
||||
(const char *string, int display_result);
|
||||
|
||||
extern char *gdbscm_safe_source_script (const char *filename);
|
||||
|
||||
|
@ -197,15 +197,10 @@ guile_command (const char *arg, int from_tty)
|
||||
|
||||
if (arg && *arg)
|
||||
{
|
||||
char *msg = gdbscm_safe_eval_string (arg, 1);
|
||||
gdb::unique_xmalloc_ptr<char> msg = gdbscm_safe_eval_string (arg, 1);
|
||||
|
||||
if (msg != NULL)
|
||||
{
|
||||
/* It is ok that this is a "dangling cleanup" because we
|
||||
throw immediately. */
|
||||
make_cleanup (xfree, msg);
|
||||
error ("%s", msg);
|
||||
}
|
||||
error ("%s", msg.get ());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -253,24 +248,16 @@ static void
|
||||
gdbscm_eval_from_control_command
|
||||
(const struct extension_language_defn *extlang, struct command_line *cmd)
|
||||
{
|
||||
char *script, *msg;
|
||||
struct cleanup *cleanup;
|
||||
char *script;
|
||||
|
||||
if (cmd->body_list_1 != nullptr)
|
||||
error (_("Invalid \"guile\" block structure."));
|
||||
|
||||
cleanup = make_cleanup (null_cleanup, NULL);
|
||||
|
||||
script = compute_scheme_string (cmd->body_list_0.get ());
|
||||
msg = gdbscm_safe_eval_string (script, 0);
|
||||
gdb::unique_xmalloc_ptr<char> msg = gdbscm_safe_eval_string (script, 0);
|
||||
xfree (script);
|
||||
if (msg != NULL)
|
||||
{
|
||||
make_cleanup (xfree, msg);
|
||||
error ("%s", msg);
|
||||
}
|
||||
|
||||
do_cleanups (cleanup);
|
||||
error ("%s", msg.get ());
|
||||
}
|
||||
|
||||
/* Read a file as Scheme code.
|
||||
|
@ -336,16 +336,12 @@ gdbscm_execute_objfile_script (const struct extension_language_defn *extlang,
|
||||
struct objfile *objfile, const char *name,
|
||||
const char *script)
|
||||
{
|
||||
char *msg;
|
||||
|
||||
ofscm_current_objfile = objfile;
|
||||
|
||||
msg = gdbscm_safe_eval_string (script, 0 /* display_result */);
|
||||
gdb::unique_xmalloc_ptr<char> msg
|
||||
= gdbscm_safe_eval_string (script, 0 /* display_result */);
|
||||
if (msg != NULL)
|
||||
{
|
||||
fprintf_filtered (gdb_stderr, "%s", msg);
|
||||
xfree (msg);
|
||||
}
|
||||
fprintf_filtered (gdb_stderr, "%s", msg.get ());
|
||||
|
||||
ofscm_current_objfile = NULL;
|
||||
}
|
||||
|
@ -393,9 +393,9 @@ scscm_eval_scheme_string (void *datap)
|
||||
and preventing continuation capture.
|
||||
The result is NULL if no exception occurred. Otherwise, the exception is
|
||||
printed according to "set guile print-stack" and the result is an error
|
||||
message allocated with malloc, caller must free. */
|
||||
message. */
|
||||
|
||||
char *
|
||||
gdb::unique_xmalloc_ptr<char>
|
||||
gdbscm_safe_eval_string (const char *string, int display_result)
|
||||
{
|
||||
struct eval_scheme_string_data data = { string, display_result };
|
||||
@ -404,7 +404,7 @@ gdbscm_safe_eval_string (const char *string, int display_result)
|
||||
result = gdbscm_with_guile (scscm_eval_scheme_string, (void *) &data);
|
||||
|
||||
if (result != NULL)
|
||||
return xstrdup (result);
|
||||
return gdb::unique_xmalloc_ptr<char> (xstrdup (result));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user