From owner-svn-src-stable@FreeBSD.ORG Tue Dec 8 19:01:05 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8562A10656A6; Tue, 8 Dec 2009 19:01:05 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 741C58FC2A; Tue, 8 Dec 2009 19:01:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nB8J15Xp096983; Tue, 8 Dec 2009 19:01:05 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nB8J15Y5096981; Tue, 8 Dec 2009 19:01:05 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <200912081901.nB8J15Y5096981@svn.freebsd.org> From: Jilles Tjoelker Date: Tue, 8 Dec 2009 19:01:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200269 - stable/7/bin/sh X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Dec 2009 19:01:05 -0000 Author: jilles Date: Tue Dec 8 19:01:05 2009 New Revision: 200269 URL: http://svn.freebsd.org/changeset/base/200269 Log: MFC r198963: sh: Fix memory leak when using a variable in arithmetic like $((x)). Modified: stable/7/bin/sh/arith_lex.l Directory Properties: stable/7/bin/sh/ (props changed) Modified: stable/7/bin/sh/arith_lex.l ============================================================================== --- stable/7/bin/sh/arith_lex.l Tue Dec 8 18:54:37 2009 (r200268) +++ stable/7/bin/sh/arith_lex.l Tue Dec 8 19:01:05 2009 (r200269) @@ -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; }