From: Michael Tremer Date: Tue, 4 May 2021 13:01:13 +0000 (+0000) Subject: parser: Attempt to fix refcounting problems X-Git-Tag: 0.9.28~1285^2~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f25d20190c6bae2dacacf253fd6377e53b312df4;p=pakfire.git parser: Attempt to fix refcounting problems This is still leaking some references and I cannot bloody find out why Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 85c347a15..6a9a34753 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -164,7 +164,18 @@ static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d struct pakfire_parser_declaration* declaration; } -%destructor { pakfire_parser_unref($$); } +%initial-action { + *parser = pakfire_parser_create(pakfire, parent, NULL, 0); + if (!*parser) + ABORT; + + // This is now the new parent parser + if (parent) + pakfire_parser_unref(parent); + parent = pakfire_parser_ref(*parser); +}; + +%destructor { if ($$) pakfire_parser_unref($$); } %destructor { pakfire_parser_free_declaration($$); } %start grammar @@ -173,16 +184,7 @@ static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d grammar : %empty { - $$ = pakfire_parser_create(pakfire, parent, NULL, 0); - if (!$$) - ABORT; - - // Make this the root - if (!*parser) - *parser = pakfire_parser_ref($$); - - // This is now the new parent parser - parent = $$; + $$ = pakfire_parser_ref(parent); } | grammar declaration { @@ -202,9 +204,6 @@ grammar : %empty pakfire_parser_unref($2); if (r) ABORT; - - // Go back to the parent parser - parent = $$; } | grammar if_stmt { @@ -216,9 +215,6 @@ grammar : %empty if (r) ABORT; } - - // Go back to the parent parser - parent = $$; } | grammar empty { @@ -226,12 +222,33 @@ grammar : %empty } ; -subgrammar : T_INDENT grammar T_OUTDENT +subgrammar_open : T_INDENT { - $$ = $2; + // Create a new parser and make it parent + PakfireParser p = pakfire_parser_create(pakfire, parent, NULL, 0); + if (!p) + ABORT; - // Go back to the parent parser - parent = $$; + if (parent) + pakfire_parser_unref(parent); + parent = p; + } + ; + +subgrammar_close : T_OUTDENT + { + // Move the parent pointer back + PakfireParser p = pakfire_parser_get_parent(parent); + + if (parent) + pakfire_parser_unref(parent); + parent = p; + } + ; + +subgrammar : subgrammar_open grammar subgrammar_close + { + $$ = $2; } ; @@ -399,7 +416,7 @@ int pakfire_parser_parse_data(PakfireParser parent, const char* data, size_t len // Destroy the parser if (parser) - pakfire_parser_unref(parser); + pakfire_parser_unref(parser); #ifdef ENABLE_DEBUG // Save end time