genconf: fix memory corruption in error cases
authorOlivier Matz <zer0@droids-corp.org>
Sun, 20 Feb 2011 16:58:01 +0000 (17:58 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 13 Mar 2011 10:09:25 +0000 (11:09 +0100)
Signed-off-by: Olivier Matz <zer0@droids-corp.org>
src/genconf/parse_confnode.c

index 033e45d..2a9ed06 100644 (file)
@@ -198,6 +198,7 @@ complete_conf_node_start(cmdline_parse_token_hdr_t *tk,
        unsigned flags = tkd->flags;
        unsigned mask = tkd->mask;
 
+       *opaque = NULL;
        cb = malloc(sizeof(*cb));
        if (cb == NULL)
                return -1;
@@ -241,7 +242,8 @@ complete_conf_node_iterate(cmdline_parse_token_hdr_t *tk, void **opaque,
 static void
 complete_conf_node_end(cmdline_parse_token_hdr_t *tk, void **opaque)
 {
-       free(*opaque);
+       if (*opaque)
+               free(*opaque);
 }
 
 int help_conf_node(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size)