summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-04-08 17:47:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-04-08 17:47:22 -0700
commitcea5c956486b8acae4bf5a23f0148d6b85d9acd3 (patch)
tree56fa09708b0fa235e8837cd1635fcfd33f3b2259
parentfb07c84eeaeda96eac369ff763dd9c1c5b5ee0fb (diff)
downloadtxr-cea5c956486b8acae4bf5a23f0148d6b85d9acd3.tar.gz
txr-cea5c956486b8acae4bf5a23f0148d6b85d9acd3.tar.bz2
txr-cea5c956486b8acae4bf5a23f0148d6b85d9acd3.zip
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.
-rw-r--r--parser.y4
1 files changed, 4 insertions, 0 deletions
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")); }
;