]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Fix refcounting
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Jun 2019 04:41:17 +0000 (05:41 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Jun 2019 04:41:17 +0000 (05:41 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser.c
src/libpakfire/parser/grammar.y

index a7c69483785f07de34af13c296b1f4eb9961c798..58064716d3a5e7a9189d74031427cbb2da903dab 100644 (file)
@@ -77,6 +77,7 @@ PAKFIRE_EXPORT PakfireParser pakfire_parser_create(Pakfire pakfire, PakfireParse
        PakfireParser parser = pakfire_calloc(1, sizeof(*parser));
        if (parser) {
                parser->pakfire = pakfire_ref(pakfire);
+               parser->nrefs = 1;
 
                // Store a reference to the parent parser if we have one
                if (parent)
index fb4df0af76116018997725f0d910940030699a78..638ec570309e3ee0337bef130808013901322998 100644 (file)
@@ -112,8 +112,8 @@ grammar                                             : grammar item
                                                        {
                                                                $$ = merge_parsers($1, $2);
 
-                                                               //pakfire_parser_unref($1);
-                                                               //pakfire_parser_unref($2);
+                                                               pakfire_parser_unref($1);
+                                                               pakfire_parser_unref($2);
                                                        }
                                                        | item
                                                        ;
@@ -181,13 +181,13 @@ end                                                       : T_END T_EOL;
 if_stmt                                                : if variable T_EQUALS variable T_EOL grammar else grammar end
                                                        {
                                                                $$ = make_if_stmt(parser, OP_EQUALS, $2, $4, $6, $8);
-                                                               //pakfire_parser_unref($6);
-                                                               //pakfire_parser_unref($8);
+                                                               pakfire_parser_unref($6);
+                                                               pakfire_parser_unref($8);
                                                        }
                                                        | if variable T_EQUALS variable T_EOL grammar end
                                                        {
                                                                $$ = make_if_stmt(parser, OP_EQUALS, $2, $4, $6, NULL);
-                                                               //pakfire_parser_unref($6);
+                                                               pakfire_parser_unref($6);
                                                        };
 
 block                                          : block_opening grammar block_closing
@@ -314,6 +314,9 @@ static PakfireParser merge_parsers(PakfireParser p1, PakfireParser p2) {
        else if (p2)
                p = p2;
 
+       if (p)
+               p = pakfire_parser_ref(p);
+
        return p;
 }