]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Fix reference counting
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 1 Mar 2021 17:39:17 +0000 (17:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 1 Mar 2021 17:39:17 +0000 (17:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y

index 1274b0751dea987cb09f6d90d11bb37f553a4334..b627d6f353e8d585a5c114a568888b8530ddec3c 100644 (file)
@@ -161,43 +161,48 @@ grammar                                           : %empty
                                                                        ABORT;
 
                                                                if (!*result)
-                                                                       *result = $$;
+                                                                       *result = pakfire_parser_ref($$);
                                                        }
                                                        | grammar declaration
                                                        {
+                                                               $$ = $1;
+
                                                                int r = pakfire_parser_apply_declaration($1, $2);
                                                                if (r)
                                                                        ABORT;
 
-                                                               $$ = pakfire_parser_ref($1);
+                                                               pakfire_parser_free_declaration($2);
                                                        }
                                                        | grammar subparser
                                                        {
+                                                               $$ = $1;
+
                                                                int r = pakfire_parser_merge($1, $2);
                                                                if (r)
                                                                        ABORT;
 
-                                                               $$ = pakfire_parser_ref($1);
+                                                               pakfire_parser_unref($2);
                                                        }
                                                        | grammar if_stmt
                                                        {
+                                                               $$ = $1;
+
                                                                if ($2) {
                                                                        int r = pakfire_parser_merge($1, $2);
+                                                                       pakfire_parser_unref($2);
                                                                        if (r)
                                                                                ABORT;
                                                                }
-
-                                                               $$ = pakfire_parser_ref($1);
                                                        }
                                                        | grammar empty
                                                        {
-                                                               $$ = pakfire_parser_ref($1);
+                                                               $$ = $1;
                                                        }
                                                        ;
 
 subgrammar                                     : T_INDENT grammar T_OUTDENT
                                                        {
-                                                               $$ = pakfire_parser_ref($2);
+                                                               $$ = $2;
                                                        }
                                                        ;
 
@@ -266,7 +271,7 @@ subparser                                   : subparser_name T_EOL subgrammar T_END T_EOL
                                                        {
                                                                pakfire_parser_set_namespace($3, $1);
 
-                                                               $$ = pakfire_parser_ref($3);
+                                                               $$ = $3;
                                                        }
                                                        | subparser_name T_EOL
                                                        {
@@ -303,12 +308,15 @@ subparser_name                            : T_SUBPARSER
 if_stmt                                                : T_IF T_STRING T_EQUALS T_STRING T_EOL subgrammar else_stmt T_END T_EOL
                                                        {
                                                                $$ = make_if_stmt(pakfire, result, OP_EQUALS, $2, $4, $6, $7);
+
+                                                               pakfire_parser_unref($6);
+                                                               pakfire_parser_unref($7);
                                                        }
                                                        ;
 
 else_stmt                                      : T_ELSE T_EOL subgrammar
                                                        {
-                                                               $$ = pakfire_parser_ref($3);
+                                                               $$ = $3;
                                                        }
                                                        | %empty
                                                        {