summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2000-01-26 22:37:25 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2000-01-26 22:37:25 +0000
commit9b9bbc943d30a3db3698b98f9de9274726ea0a76 (patch)
tree703f9846e9c8810b0272ba69a487b49946e6fd78
parente46b9feab42337e8d5f5852529fa0be488a2496e (diff)
if yygrowstack() fails to allocate memory, free all yacc memory allocations and reset for future yyparse() calls... obscure eh
-rw-r--r--usr.bin/yacc/skeleton.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/usr.bin/yacc/skeleton.c b/usr.bin/yacc/skeleton.c
index c2c55d079f4..d6183da3371 100644
--- a/usr.bin/yacc/skeleton.c
+++ b/usr.bin/yacc/skeleton.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: skeleton.c,v 1.13 1998/11/18 15:45:12 dm Exp $ */
+/* $OpenBSD: skeleton.c,v 1.14 2000/01/26 22:37:24 deraadt Exp $ */
/* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */
/*
@@ -67,7 +67,7 @@ char *banner[] =
"#if __GNUC__ == 2",
" __attribute__ ((unused))",
"#endif /* __GNUC__ == 2 */",
- " = \"$OpenBSD: skeleton.c,v 1.13 1998/11/18 15:45:12 dm Exp $\";",
+ " = \"$OpenBSD: skeleton.c,v 1.14 2000/01/26 22:37:24 deraadt Exp $\";",
"#endif",
"#include <stdlib.h>",
"#define YYBYACC 1",
@@ -154,18 +154,26 @@ char *body[] =
" newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
" (short *)malloc(newsize * sizeof *newss);",
" if (newss == NULL)",
- " return -1;",
+ " goto bail;",
" yyss = newss;",
" yyssp = newss + i;",
" newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
" (YYSTYPE *)malloc(newsize * sizeof *newvs);",
" if (newvs == NULL)",
- " return -1;",
+ " goto bail;",
" yyvs = newvs;",
" yyvsp = newvs + i;",
" yystacksize = newsize;",
" yysslim = yyss + newsize - 1;",
" return 0;",
+ "bail:",
+ " if (yyss)",
+ " free(yyss);",
+ " if (yyvs)",
+ " free(yyvs);",
+ " yyss = yyssp = yyvs = yyvsp = NULL;",
+ " yystacksize = 0;",
+ " return -1;",
"}",
"",
"#define YYABORT goto yyabort",