svn commit: r200188 - stable/8/bin/sh
Oliver Pinter
oliver.pntr at gmail.com
Sun Dec 6 22:46:43 UTC 2009
this for 7-STABLE?
On 12/6/09, Jilles Tjoelker <jilles at freebsd.org> wrote:
> Author: jilles
> Date: Sun Dec 6 22:01:45 2009
> New Revision: 200188
> URL: http://svn.freebsd.org/changeset/base/200188
>
> Log:
> MFC r198963: sh: Fix memory leak when using a variable in arithmetic
> like $((x)).
>
> Modified:
> stable/8/bin/sh/arith_lex.l
> Directory Properties:
> stable/8/bin/sh/ (props changed)
>
> Modified: stable/8/bin/sh/arith_lex.l
> ==============================================================================
> --- stable/8/bin/sh/arith_lex.l Sun Dec 6 21:42:25 2009 (r200187)
> +++ stable/8/bin/sh/arith_lex.l Sun Dec 6 22:01:45 2009 (r200188)
> @@ -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;
> }
> _______________________________________________
> svn-src-stable at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/svn-src-stable
> To unsubscribe, send any mail to "svn-src-stable-unsubscribe at freebsd.org"
>
More information about the svn-src-all
mailing list