Close memory leak in lexer.
authorCarl Worth <cworth@cworth.org>
Sat, 19 Jun 2010 00:43:40 +0000 (17:43 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 24 Jun 2010 02:00:42 +0000 (19:00 -0700)
Simply call talloc_strdup rather than strdup, (using the talloc_parent
of our 'state' object, (known here as yyextra).

This fix now makes glsl-orangebook-ch06-bump.frag 99.97% leak free:

total heap usage: 55,623 allocs, 55,609 frees

Only 14 missing frees now.

glsl_lexer.lpp

index c15c99c..fa439f1 100644 (file)
@@ -312,7 +312,9 @@ highp               return HIGHP;
 precision      return PRECISION;
 
 [_a-zA-Z][_a-zA-Z0-9]* {
-                           yylval->identifier = strdup(yytext);
+                           struct _mesa_glsl_parse_state *state = yyextra;
+                           void *ctx = talloc_parent(state);   
+                           yylval->identifier = talloc_strdup(ctx, yytext);
                            return IDENTIFIER;
                        }