lib: Fix uninitialized pointer segfault

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2016-09-08 21:07:55 +00:00
parent ff35126c06
commit fe2e10e8d8
2 changed files with 10 additions and 10 deletions

View File

@ -453,13 +453,7 @@ doc_next()
static struct graph_node * static struct graph_node *
new_token_node (struct graph *graph, enum cmd_token_type_t type, char *text, char *doc) new_token_node (struct graph *graph, enum cmd_token_type_t type, char *text, char *doc)
{ {
struct cmd_token_t *token = struct cmd_token_t *token = new_cmd_token (type, text, doc);
XMALLOC (MTYPE_CMD_TOKENS, sizeof (struct cmd_token_t));
token->type = type;
token->text = text;
token->desc = doc;
return graph_new_node (graph, token, (void (*)(void *)) &del_cmd_token); return graph_new_node (graph, token, (void (*)(void *)) &del_cmd_token);
} }

View File

@ -289,9 +289,15 @@ 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)
{ {
if (!token) return;
if (token->text)
XFREE (MTYPE_CMD_TOKENS, token->text); XFREE (MTYPE_CMD_TOKENS, token->text);
if (token->desc)
XFREE (MTYPE_CMD_TOKENS, token->desc); XFREE (MTYPE_CMD_TOKENS, token->desc);
if (token->arg)
XFREE (MTYPE_CMD_TOKENS, token->arg); XFREE (MTYPE_CMD_TOKENS, token->arg);
XFREE (MTYPE_CMD_TOKENS, token); XFREE (MTYPE_CMD_TOKENS, token);
} }