]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Fix uninitialized pointer segfault
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 8 Sep 2016 21:07:55 +0000 (21:07 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 8 Sep 2016 21:07:55 +0000 (21:07 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command_parse.y
lib/grammar_sandbox.c

index 1ee5afc65e8445360cefca3053a4c27bc317a3f2..a5d391d19e2072ac0f4df9f0066b6bbe11f87aba 100644 (file)
@@ -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);
 }
 
index fe01c113d2a41c5db9094f65c4292d257c99b477..6a783a6d5611e871c00a2db167801965e5b0b7ad 100644 (file)
@@ -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);
 }