]> git.ipfire.org Git - pakfire.git/commitdiff
parser: grammar: Ensure we always free a dumped parser
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 4 Oct 2023 16:02:44 +0000 (16:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 4 Oct 2023 16:02:44 +0000 (16:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y

index 7da6578432af5df2b674d0b85b39341c62d83588..8d394f84f7f99e3c2152b9b23f577c73779d6db0 100644 (file)
@@ -407,6 +407,7 @@ else_stmt                                   : T_ELSE T_EOL block
 int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, size_t len,
                struct pakfire_parser_error** error) {
        struct pakfire* pakfire = pakfire_parser_get_pakfire(parent);
+       char* dump = NULL;
        yyscan_t scanner;
 
        // Initialize the parser's state
@@ -452,10 +453,9 @@ int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, s
        clock_t t_end = clock();
 
        // Log what we have in the parent parser now
-       char* dump = pakfire_parser_dump(parent);
-
-       DEBUG(pakfire, "Status of the parser %p:\n%s\n", parent, dump);
-       free(dump);
+       dump = pakfire_parser_dump(parent);
+       if (dump)
+               DEBUG(pakfire, "Status of the parser %p:\n%s\n", parent, dump);
 
        // Log time we needed to parse data
        DEBUG(pakfire, "Parser finished in %.4fms\n",
@@ -463,6 +463,8 @@ int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, s
 #endif
 
        // Cleanup
+       if (dump)
+               free(dump);
        pakfire_unref(pakfire);
        yylex_destroy(scanner);