summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-04-06 09:12:03 +0200
committerDave Davenport <qball@gmpclient.org>2017-04-06 09:12:03 +0200
commit898b5466f0ba83dbe098ca40bf0d3bdda47f5033 (patch)
treec391965f3aaddb6d4cb5005bd12f177451141d2c
parent387093a67367b6a0b4c6e0117ac664369bd615f4 (diff)
Fix memory leak on parser fail.
-rw-r--r--lexer/theme-lexer.l16
-rw-r--r--test/theme-parser-test.c1
2 files changed, 17 insertions, 0 deletions
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 );