mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-12 14:27:36 +00:00
lib: Fix various memory leaks
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
67c02c9449
commit
795d02785a
@ -101,14 +101,17 @@ command_match (struct graph *cmdgraph,
|
|||||||
struct graph_node *start = vector_slot (cmdgraph->nodes, 0);
|
struct graph_node *start = vector_slot (cmdgraph->nodes, 0);
|
||||||
if ((*argv = command_match_r (start, vvline, 0))) // successful match
|
if ((*argv = command_match_r (start, vvline, 0))) // successful match
|
||||||
{
|
{
|
||||||
// delete dummy start node
|
struct listnode *head = listhead (*argv);
|
||||||
list_delete_node (*argv, listhead (*argv));
|
|
||||||
// get cmd_element out of list tail
|
|
||||||
struct listnode *tail = listtail (*argv);
|
struct listnode *tail = listtail (*argv);
|
||||||
|
|
||||||
|
// delete dummy start node
|
||||||
|
del_cmd_token ((struct cmd_token_t *) head->data);
|
||||||
|
list_delete_node (*argv, head);
|
||||||
|
|
||||||
|
// get cmd_element out of list tail
|
||||||
*el = listgetdata (tail);
|
*el = listgetdata (tail);
|
||||||
// delete list tail
|
|
||||||
tail->data = NULL;
|
|
||||||
list_delete_node (*argv, tail);
|
list_delete_node (*argv, tail);
|
||||||
|
|
||||||
// now argv is an ordered list of cmd_token matching the user
|
// now argv is an ordered list of cmd_token matching the user
|
||||||
// input, with each cmd_token->arg holding the corresponding input
|
// input, with each cmd_token->arg holding the corresponding input
|
||||||
assert (*el);
|
assert (*el);
|
||||||
@ -290,7 +293,7 @@ command_complete (struct graph *graph,
|
|||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
for (idx = 0; idx < vector_active (vline) && next->count > 0; idx++)
|
for (idx = 0; idx < vector_active (vline) && next->count > 0; idx++)
|
||||||
{
|
{
|
||||||
list_free (current);
|
list_delete (current);
|
||||||
current = next;
|
current = next;
|
||||||
next = list_new();
|
next = list_new();
|
||||||
|
|
||||||
@ -334,8 +337,8 @@ command_complete (struct graph *graph,
|
|||||||
for (ALL_LIST_ELEMENTS_RO (next,node,gn))
|
for (ALL_LIST_ELEMENTS_RO (next,node,gn))
|
||||||
listnode_add (*completions, gn->data);
|
listnode_add (*completions, gn->data);
|
||||||
|
|
||||||
list_free (current);
|
list_delete (current);
|
||||||
list_free (next);
|
list_delete (next);
|
||||||
|
|
||||||
return matcher_rv;
|
return matcher_rv;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ DEFUN (grammar_test_complete,
|
|||||||
vector command = cmd_make_strvec (cmdstr);
|
vector command = cmd_make_strvec (cmdstr);
|
||||||
|
|
||||||
// generate completions of user input
|
// generate completions of user input
|
||||||
struct list *completions = list_new ();
|
struct list *completions;
|
||||||
enum matcher_rv result = command_complete (nodegraph, command, &completions);
|
enum matcher_rv result = command_complete (nodegraph, command, &completions);
|
||||||
|
|
||||||
// print completions or relevant error message
|
// print completions or relevant error message
|
||||||
@ -106,6 +106,10 @@ DEFUN (grammar_test_complete,
|
|||||||
tkn = vector_slot (comps, i);
|
tkn = vector_slot (comps, i);
|
||||||
fprintf (stdout, " %-*s %s%s", width, tkn->text, tkn->desc, "\n");
|
fprintf (stdout, " %-*s %s%s", width, tkn->text, tkn->desc, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < vector_active (comps); i++)
|
||||||
|
del_cmd_token ((struct cmd_token_t *) vector_slot (comps, i));
|
||||||
|
vector_free (comps);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fprintf (stdout, "%% No match%s", "\n");
|
fprintf (stdout, "%% No match%s", "\n");
|
||||||
@ -147,6 +151,7 @@ DEFUN (grammar_test_match,
|
|||||||
fprintf (stdout, "func: %p%s", element->func, "\n");
|
fprintf (stdout, "func: %p%s", element->func, "\n");
|
||||||
|
|
||||||
list_delete (argvv);
|
list_delete (argvv);
|
||||||
|
del_cmd_element (element);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(MATCHER_ERROR(result));
|
assert(MATCHER_ERROR(result));
|
||||||
@ -351,6 +356,7 @@ new_cmd_token (enum cmd_token_type_t type, char *text, char *desc)
|
|||||||
void
|
void
|
||||||
del_cmd_token (struct cmd_token_t *token)
|
del_cmd_token (struct cmd_token_t *token)
|
||||||
{
|
{
|
||||||
|
fprintf (stdout, "deleting token\n");
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
|
|
||||||
if (token->text)
|
if (token->text)
|
||||||
|
Loading…
Reference in New Issue
Block a user