gdb/guile: remove some manual xfree calls
Commit Message
While working on another patch I had reason to look at
gdbscm_lookup_type, and noticed that we were making some manual calls
to xfree.
This commit switches to using gdb::unique_xmalloc_ptr<char> which
should automate the xfree calls. I don't believe that we were leaking
memory before this commit -- this is just a cleanup.
There should be no user visible changes after this commit.
---
gdb/guile/scm-type.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
base-commit: e9683acf5e51c2bac8aa68d30d9ac3683dddcc7d
Comments
>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
Andrew> if (block == NULL)
Andrew> - {
Andrew> - xfree (name);
Andrew> - gdbscm_throw (exception);
Andrew> - }
Andrew> + gdbscm_throw (exception);
Unfortunately I don't think this is the same. IIUC, gdbscm_throw is a
noreturn function that calls longjmp. So, the destructor will never be
run.
Tom
Tom Tromey <tom@tromey.com> writes:
>>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Andrew> if (block == NULL)
> Andrew> - {
> Andrew> - xfree (name);
> Andrew> - gdbscm_throw (exception);
> Andrew> - }
> Andrew> + gdbscm_throw (exception);
>
> Unfortunately I don't think this is the same. IIUC, gdbscm_throw is a
> noreturn function that calls longjmp. So, the destructor will never be
> run.
You are correct. Thanks for pointing this out.
Thanks,
Andrew
@@ -1267,15 +1267,16 @@ static SCM
gdbscm_lookup_type (SCM name_scm, SCM rest)
{
SCM keywords[] = { block_keyword, SCM_BOOL_F };
- char *name;
+ char *name_str;
SCM block_scm = SCM_BOOL_F;
int block_arg_pos = -1;
const struct block *block = NULL;
struct type *type;
gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#O",
- name_scm, &name,
+ name_scm, &name_str,
rest, &block_arg_pos, &block_scm);
+ gdb::unique_xmalloc_ptr<char> name (name_str);
if (block_arg_pos != -1)
{
@@ -1284,13 +1285,9 @@ gdbscm_lookup_type (SCM name_scm, SCM rest)
block = bkscm_scm_to_block (block_scm, block_arg_pos, FUNC_NAME,
&exception);
if (block == NULL)
- {
- xfree (name);
- gdbscm_throw (exception);
- }
+ gdbscm_throw (exception);
}
- type = tyscm_lookup_typename (name, block);
- xfree (name);
+ type = tyscm_lookup_typename (name.get (), block);
if (type != NULL)
return tyscm_scm_from_type (type);