Date: Thu, 5 Nov 2009 20:44:39 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r198963 - head/bin/sh Message-ID: <200911052044.nA5KidiH090202@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Thu Nov 5 20:44:39 2009 New Revision: 198963 URL: http://svn.freebsd.org/changeset/base/198963 Log: sh: Fix memory leak when using a variable in arithmetic like $((x)). MFC after: 3 weeks Modified: head/bin/sh/arith_lex.l Modified: head/bin/sh/arith_lex.l ============================================================================== --- head/bin/sh/arith_lex.l Thu Nov 5 19:55:42 2009 (r198962) +++ head/bin/sh/arith_lex.l Thu Nov 5 20:44:39 2009 (r198963) @@ -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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200911052044.nA5KidiH090202>