summaryrefslogtreecommitdiff
path: root/lib/grammar_sandbox.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-07-29 15:54:03 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-07-29 15:54:03 +0000
commitde9d7e4f3ccb1b199602c1a1ce884df37e54f834 (patch)
tree7ecb990ffe55f28e5ce77a059c791f558e503130 /lib/grammar_sandbox.c
parent76699ae7e0358c57a1186b88962d7233a7057d76 (diff)
lib: Cleanup some memory issues in CLI
Various memory leaks have been fixed and the quagga memory macros are in use. Also consolidated the argv and matching code into one graph traversal. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/grammar_sandbox.c')
-rw-r--r--lib/grammar_sandbox.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c
index e4617969af..2443b8471c 100644
--- a/lib/grammar_sandbox.c
+++ b/lib/grammar_sandbox.c
@@ -18,7 +18,6 @@ DEFUN (grammar_test,
struct cmd_element *cmd = malloc(sizeof(struct cmd_element));
cmd->string = command;
parse_command_format(nodegraph, cmd);
- walk_graph(nodegraph, 0);
return CMD_SUCCESS;
}
@@ -28,6 +27,10 @@ DEFUN (grammar_test_show,
GRAMMAR_STR
"print current accumulated DFA\n")
{
+ if (!nodegraph)
+ fprintf(stderr, "!nodegraph\n");
+ fprintf(stderr, "trying to print nodegraph->type\n");
+ fprintf(stderr, "%d\n", nodegraph->type);
walk_graph(nodegraph, 0);
return CMD_SUCCESS;
}
@@ -59,7 +62,7 @@ DEFUN (grammar_test_complete,
}
free(desc);
}
- list_free(result);
+ list_delete(result);
return CMD_SUCCESS;
}
@@ -71,24 +74,22 @@ DEFUN (grammar_test_match,
"attempt to match input on DFA\n"
"command to match")
{
- const char* command = argv_concat(argv, argc, 0);
- struct cmd_element *element = match_command (nodegraph, command, FILTER_STRICT);
+ struct list *argvv = NULL;
+ const char *command = argv_concat(argv, argc, 0);
+ struct cmd_element *element = match_command (nodegraph, command, &argvv);
- if (element)
+ if (element) {
fprintf(stderr, "Matched: %s\n", element->string);
- else {
- fprintf(stderr, "Returned NULL\n");
- return CMD_SUCCESS;
- }
-
- struct list *argvv = match_build_argv (command, element);
- if (!argvv) fprintf(stderr, "Failed to build argv.\n");
- else {
struct listnode *ln;
struct graph_node *gn;
for (ALL_LIST_ELEMENTS_RO(argvv,ln,gn))
fprintf(stderr, "%s -- %s\n", gn->text, gn->arg);
}
+ else {
+ fprintf(stderr, "Returned NULL\n");
+ return CMD_SUCCESS;
+ }
+
return CMD_SUCCESS;
}