diff options
author | Pierre Muller <muller@sourceware.org> | 2012-12-05 23:23:22 +0000 |
---|---|---|
committer | Pierre Muller <muller@sourceware.org> | 2012-12-05 23:23:22 +0000 |
commit | 5bc81a00b656522351c5970a4e7546e9b68870a1 (patch) | |
tree | 4b6e39064f76d1eb399f55b75c5021d249afec47 /gdb/cli/cli-decode.c | |
parent | ad288036a73ad7fa77b75522c3e06eaef70b2e57 (diff) | |
download | gdb-5bc81a00b656522351c5970a4e7546e9b68870a1.zip gdb-5bc81a00b656522351c5970a4e7546e9b68870a1.tar.gz gdb-5bc81a00b656522351c5970a4e7546e9b68870a1.tar.bz2 |
Avoid memory leaks on struct cmd_list_element.doc field.
* cli/cli-decode.c (add_alias_cmd): Make a copy of doc field
if flags contains DOC_ALLOCATED.
(add_setshow_cmd_full): Add DOC_ALLOCATED to set and show
flags.
(delete_cmd): Handle DOC_ALLOCATED flag.
* cli/cli-decode.h (DOC_ALLOCATED): New macro for use
in flags filed of struct cmd_list_element.
(struct cmd_list_element): Document new flag item.
Diffstat (limited to 'gdb/cli/cli-decode.c')
-rw-r--r-- | gdb/cli/cli-decode.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 3de01d5..6dd4180 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -306,6 +306,13 @@ add_alias_cmd (char *name, char *oldname, enum command_class class, } c = add_cmd (name, class, NULL, old->doc, list); + + /* If OLD->DOC can be freed, we should make another copy. */ + if ((old->flags & DOC_ALLOCATED) != 0) + { + c->doc = xstrdup (old->doc); + c->flags |= DOC_ALLOCATED; + } /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */ c->func = old->func; c->function = old->function; @@ -451,6 +458,8 @@ add_setshow_cmd_full (char *name, } set = add_set_or_show_cmd (name, set_cmd, class, var_type, var, full_set_doc, set_list); + set->flags |= DOC_ALLOCATED; + if (set_func != NULL) set_cmd_sfunc (set, set_func); @@ -458,6 +467,7 @@ add_setshow_cmd_full (char *name, show = add_set_or_show_cmd (name, show_cmd, class, var_type, var, full_show_doc, show_list); + show->flags |= DOC_ALLOCATED; show->show_value_func = show_func; if (set_result != NULL) @@ -769,6 +779,8 @@ delete_cmd (char *name, struct cmd_list_element **list, *prehookee = iter->hookee_pre; if (iter->hookee_post) iter->hookee_post->hook_post = 0; + if (iter->doc && (iter->flags & DOC_ALLOCATED) != 0) + xfree (iter->doc); *posthook = iter->hook_post; *posthookee = iter->hookee_post; |