[Mesa-dev] [PATCH] glsl: Fix memory leak in glsl_lexer.ll

Ian Romanick idr at freedesktop.org
Tue Sep 9 12:36:44 PDT 2014


On 09/05/2014 06:22 AM, Juha-Pekka Heikkila wrote:
> Running fast clear glClear with SNB caused Valgrind to
> complain about this.
> 
> v2: line 237 fixed glClear from leaking memory, other
> strdups are also now changed to ralloc_strdups but I
> don't know what effect those have. At least no changes in
> my Piglit quick run.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/glsl/glsl_lexer.ll | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/glsl/glsl_lexer.ll b/src/glsl/glsl_lexer.ll
> index b7c4aad..9cf57dd 100644
> --- a/src/glsl/glsl_lexer.ll
> +++ b/src/glsl/glsl_lexer.ll
> @@ -81,7 +81,8 @@ static int classify_identifier(struct _mesa_glsl_parse_state *, const char *);
>  			  "illegal use of reserved word `%s'", yytext);	\
>  	 return ERROR_TOK;						\
>        } else {								\
> -	 yylval->identifier = strdup(yytext);				\
> +	 void *ctx = yyextra;								\
> +	 yylval->identifier = ralloc_strdup(ctx, yytext);	\

It seems a little weird to do this as two lines.  Why not

	 yylval->identifier = ralloc_strdup(yyextra, yytext);

Also, we're trying to use mem_ctx for the ralloc memory context.  Using
just ctx was confusing in many places because the GL context is also
usually named ctx.

Either s/ctx/mem_ctx/ or do it in one line to get a

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

>  	 return classify_identifier(yyextra, yytext);			\
>        }									\
>     } while (0)
> @@ -232,7 +233,8 @@ HASH		^{SPC}#{SPC}
>  <PP>[ \t\r]*			{ }
>  <PP>:				return COLON;
>  <PP>[_a-zA-Z][_a-zA-Z0-9]*	{
> -				   yylval->identifier = strdup(yytext);
> +				   void *ctx = yyextra;
> +				   yylval->identifier = ralloc_strdup(ctx, yytext);
>  				   return IDENTIFIER;
>  				}
>  <PP>[1-9][0-9]*			{
> @@ -409,7 +411,8 @@ layout		{
>                        || yyextra->ARB_compute_shader_enable) {
>  		      return LAYOUT_TOK;
>  		   } else {
> -		      yylval->identifier = strdup(yytext);
> +		      void *ctx = yyextra;
> +		      yylval->identifier = ralloc_strdup(ctx, yytext);
>  		      return classify_identifier(yyextra, yytext);
>  		   }
>  		}
> 



More information about the mesa-dev mailing list