summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2009-11-05 20:44:39 +0000
committerjilles <jilles@FreeBSD.org>2009-11-05 20:44:39 +0000
commitb7d759e2ccf64c56e17c806c07398a5a7090df00 (patch)
treed56b1fb910d1b178cf02443d1fe7276a02e7e142 /bin
parentacdf1c7b900c647bc83f8af0dadc1e0b67938cc7 (diff)
downloadFreeBSD-src-b7d759e2ccf64c56e17c806c07398a5a7090df00.zip
FreeBSD-src-b7d759e2ccf64c56e17c806c07398a5a7090df00.tar.gz
sh: Fix memory leak when using a variable in arithmetic like $((x)).
MFC after: 3 weeks
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/arith_lex.l26
1 files changed, 23 insertions, 3 deletions
diff --git a/bin/sh/arith_lex.l b/bin/sh/arith_lex.l
index f0ed3d5..f0d9cb3 100644
--- a/bin/sh/arith_lex.l
+++ b/bin/sh/arith_lex.l
@@ -51,6 +51,13 @@ __FBSDID("$FreeBSD$");
int yylex(void);
+struct varname
+{
+ struct varname *next;
+ char name[1];
+};
+static struct varname *varnames;
+
#undef YY_INPUT
#define YY_INPUT(buf,result,max) \
result = (*buf = *arith_buf++) ? 1 : YY_NULL;
@@ -80,11 +87,14 @@ int yylex(void);
* If variable doesn't exist, we should initialize
* it to zero.
*/
- char *temp;
+ struct varname *temp;
if (lookupvar(yytext) == NULL)
setvarsafe(yytext, "0", 0);
- temp = (char *)ckmalloc(strlen(yytext) + 1);
- yylval.s_value = strcpy(temp, yytext);
+ temp = ckmalloc(sizeof(struct varname) +
+ strlen(yytext));
+ temp->next = varnames;
+ varnames = temp;
+ yylval.s_value = strcpy(temp->name, yytext);
return ARITH_VAR;
}
@@ -130,5 +140,15 @@ int yylex(void);
void
arith_lex_reset(void)
{
+ struct varname *name, *next;
+
YY_NEW_FILE;
+
+ name = varnames;
+ while (name != NULL) {
+ next = name->next;
+ ckfree(name);
+ name = next;
+ }
+ varnames = NULL;
}
OpenPOWER on IntegriCloud