From 898b5466f0ba83dbe098ca40bf0d3bdda47f5033 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 6 Apr 2017 09:12:03 +0200 Subject: [PATCH] Fix memory leak on parser fail. --- lexer/theme-lexer.l | 16 ++++++++++++++++ test/theme-parser-test.c | 1 + 2 files changed, 17 insertions(+) diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index a4d3b8e1..2a9709db 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -573,6 +573,14 @@ gboolean rofi_theme_parse_file ( const char *file ) yylex_destroy (); yyin = NULL; + while ( (po = g_queue_pop_head ( file_queue ) )) { + if ( po ) { + if ( po->type == PT_FILE ){ + fclose ( po->filein ); + } + g_free ( po ); + } + } // Free up. g_list_foreach ( imported_files, (GFunc)g_free, NULL); g_list_free ( imported_files ); @@ -601,6 +609,14 @@ gboolean rofi_theme_parse_string ( const char *string ) int parser_retv = yyparse ( string ); yylex_destroy (); + while ( (po = g_queue_pop_head ( file_queue ) )) { + if ( po ) { + if ( po->type == PT_FILE ){ + fclose ( po->filein ); + } + g_free ( po ); + } + } // Free up. g_list_foreach ( imported_files, (GFunc)g_free, NULL); g_list_free ( imported_files ); diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 11609267..c1b64503 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -86,6 +86,7 @@ int main ( int argc, char ** argv ) TASSERT ( rofi_theme != NULL ); rofi_theme_free ( rofi_theme ); rofi_theme = NULL; + rofi_theme_parse_string ( " Blaat "); TASSERT ( rofi_theme != NULL ); TASSERT ( error == TRUE );