summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-09-08 21:07:55 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-09-08 21:07:55 +0000
commitfe2e10e8d85990079da100fa0e2646a436cf3602 (patch)
tree05bf0d9166cebe6c816e3f4cda3d6d25dab28792 /lib
parentff35126c0661e4b869f3c4782c02605a7f226e18 (diff)
lib: Fix uninitialized pointer segfault
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/command_parse.y8
-rw-r--r--lib/grammar_sandbox.c12
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/command_parse.y b/lib/command_parse.y
index 1ee5afc65e..a5d391d19e 100644
--- a/lib/command_parse.y
+++ b/lib/command_parse.y
@@ -453,13 +453,7 @@ doc_next()
static struct graph_node *
new_token_node (struct graph *graph, enum cmd_token_type_t type, char *text, char *doc)
{
- struct cmd_token_t *token =
- XMALLOC (MTYPE_CMD_TOKENS, sizeof (struct cmd_token_t));
-
- token->type = type;
- token->text = text;
- token->desc = doc;
-
+ struct cmd_token_t *token = new_cmd_token (type, text, doc);
return graph_new_node (graph, token, (void (*)(void *)) &del_cmd_token);
}
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c
index fe01c113d2..6a783a6d56 100644
--- a/lib/grammar_sandbox.c
+++ b/lib/grammar_sandbox.c
@@ -289,9 +289,15 @@ new_cmd_token (enum cmd_token_type_t type, char *text, char *desc)
void
del_cmd_token (struct cmd_token_t *token)
{
- XFREE (MTYPE_CMD_TOKENS, token->text);
- XFREE (MTYPE_CMD_TOKENS, token->desc);
- XFREE (MTYPE_CMD_TOKENS, token->arg);
+ if (!token) return;
+
+ if (token->text)
+ XFREE (MTYPE_CMD_TOKENS, token->text);
+ if (token->desc)
+ XFREE (MTYPE_CMD_TOKENS, token->desc);
+ if (token->arg)
+ XFREE (MTYPE_CMD_TOKENS, token->arg);
+
XFREE (MTYPE_CMD_TOKENS, token);
}