From: Michael Tremer Date: Wed, 4 Oct 2023 16:02:44 +0000 (+0000) Subject: parser: grammar: Ensure we always free a dumped parser X-Git-Tag: 0.9.30~1553 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44ab277d8b90c003c940c34c36b6135a47dc4390;p=pakfire.git parser: grammar: Ensure we always free a dumped parser Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 7da657843..8d394f84f 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -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);