From 8d8cf5e3220bad44641d27b9eafbe7c5c4b2c41a Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 8 Sep 2016 23:53:06 +0000 Subject: [PATCH] lib: Fix dangling pointer in matcher Signed-off-by: Quentin Young --- lib/command_match.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/command_match.c b/lib/command_match.c index 0b8cc99219..68dda6f9cd 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -225,12 +225,9 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n) struct list *newbest = disambiguate (currbest, result, vline, n+1); // set ambiguity flag ambiguous = !newbest || (ambiguous && newbest == currbest); - // choose the list to be deleted + // delete the unnecessary result struct list *todelete = ((newbest && newbest == result) ? currbest : result); - // manually delete the last node, which has a cmd_element - del_cmd_element (listgetdata (listtail (todelete))); - // use the list->del callback to delete the rest of the list - list_delete (todelete); + del_arglist (todelete); currbest = newbest ? newbest : currbest; } @@ -243,6 +240,7 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n) if (ambiguous) { del_arglist (currbest); + currbest = NULL; matcher_rv = MATCHER_AMBIGUOUS; } else @@ -250,7 +248,7 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n) // copy token, set arg and prepend to currbest struct cmd_token_t *token = start->data; struct cmd_token_t *copy = copy_cmd_token (token); - copy->arg = XSTRDUP(MTYPE_CMD_TOKENS, input_token); + copy->arg = XSTRDUP (MTYPE_CMD_TOKENS, input_token); list_add_node_prev (currbest, currbest->head, copy); matcher_rv = MATCHER_OK; } -- 2.39.5