From cea5c956486b8acae4bf5a23f0148d6b85d9acd3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 8 Apr 2021 17:47:22 -0700 Subject: parser: fix few memory leaks in error recovery. * parser.y (var, o_var): In a few error productions in which we have a SYMTOK item, we should free the lexeme. This doesn't solve all leaks: any time we have a parser stack containing SYMTOK or TEXT items that belong to rules that have not yet been reduced, and the parse job is aborted due to errors, we leak those. --- parser.y | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/parser.y b/parser.y index 661200dd..7e5b898d 100644 --- a/parser.y +++ b/parser.y @@ -818,13 +818,16 @@ var : SYMTOK { $$ = list(var_s, symhlpr($1, nil), nao); } | var_op SYMTOK { $$ = list(var_s, symhlpr($2, nil), $1, nao); } | var_op '{' SYMTOK '}' { $$ = list(var_s, symhlpr($3, nil), $1, nao); } | var_op '{' SYMTOK regex '}' { $$ = nil; + free($3); yyerr("longest match " "not useable with regex"); } | var_op '{' SYMTOK NUMBER '}' { $$ = nil; + free($3); yyerr("longest match " "not useable with " "fixed width match"); } | SYMTOK error { $$ = nil; + free($1); yybadtok(yychar, lit("variable spec")); } | var_op error { $$ = nil; yybadtok(yychar, lit("variable spec")); } @@ -856,6 +859,7 @@ o_var : SYMTOK { val expr = symhlpr($1, nil); val quasi_items = cons(quasi_var, nil); $$ = car(expand_quasi(quasi_items, nil)); } } | SYMTOK error { $$ = nil; + free($1); yybadtok(yychar, lit("variable spec")); } ; -- cgit v1.2.3