]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
scanner: free filename when destroying scanner
authorEric Leblond <eric@regit.org>
Mon, 10 Jul 2017 22:32:54 +0000 (00:32 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 17 Jul 2017 15:20:34 +0000 (17:20 +0200)
To be able to do so we duplicate the name in the indesc if it is
set.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/erec.c
src/scanner.l

index eacdd97a21cbc2c035947b1d1804a7b29f1b236e..439add97c4e0b9d2270e81cad4659aaa737eeb25 100644 (file)
@@ -39,6 +39,8 @@ static void input_descriptor_destroy(const struct input_descriptor *indesc)
            indesc->location.indesc->type != INDESC_INTERNAL) {
                input_descriptor_destroy(indesc->location.indesc);
        }
+       if (indesc->name)
+               xfree(indesc->name);
        xfree(indesc);
 }
 
@@ -53,6 +55,9 @@ static struct input_descriptor *input_descriptor_dup(const struct input_descript
            indesc->location.indesc->type != INDESC_INTERNAL)
                dup_indesc->location.indesc = input_descriptor_dup(indesc->location.indesc);
 
+       if (indesc->name)
+               dup_indesc->name = xstrdup(indesc->name);
+
        return dup_indesc;
 }
 
index 86a03f3b3bdbaf630000e5952198b92a6138c055..7d5437f123ce09cecfdc4cc01879354edeec6896 100644 (file)
@@ -835,6 +835,7 @@ void scanner_push_buffer(void *scanner, const struct input_descriptor *indesc,
        state->indesc = &state->indescs[state->indesc_idx++];
        memcpy(state->indesc, indesc, sizeof(*state->indesc));
        state->indesc->data = buffer;
+       state->indesc->name = NULL;
 
        b = yy_scan_string(buffer, scanner);
        assert(b != NULL);
@@ -858,9 +859,15 @@ void scanner_destroy(struct parser_state *scanner)
 {
        struct parser_state *state = yyget_extra(scanner);
 
-       /* Can't free indesc name - locations might still be in use */
-       while (state->indesc_idx--)
+       do {
+               struct input_descriptor *inpdesc =
+                       &state->indescs[state->indesc_idx];
+               if (inpdesc && inpdesc->name) {
+                       xfree(inpdesc->name);
+                       inpdesc->name = NULL;
+               }
                yypop_buffer_state(scanner);
+       } while (state->indesc_idx--);
 
        yylex_destroy(scanner);
 }