<div dir="ltr">On 28 August 2013 05:26, Aras Pranckevicius <span dir="ltr"><<a href="mailto:aras@unity3d.com" target="_blank">aras@unity3d.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">Hi,<div><br></div><div>Looking at the code, is there a potential memory leak in GLSL parser wrt extension statements?</div><div><br></div>glsl_lexer.ll has:<br> <PP>[_a-zA-Z][_a-zA-Z0-9]* {<br> yylval->identifier = strdup(yytext);<br>
return IDENTIFIER;<br> }<div><br><div>i.e. calls strdup on the token (there's one other place that calls strdup; whereas most regular identifiers use <span style="font-size:13px">ralloc_strdup for easier memory management.</span></div>
<div><br><div><br></div><div>glsl_parser.yy has this:</div><div><br></div><div><pre style="padding:0px;margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"> extension_statement:<br> EXTENSION any_identifier COLON any_identifier EOL<br>
{<br> if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {<br> YYERROR;<br> }<br> }<br> ;</font></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px"><br></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px">
<font face="arial, helvetica, sans-serif">which looks like it processes the extension identifiers, but never frees the memory.</font></pre><span class=""><font color="#888888"><pre style="padding:0px;margin-top:0px;margin-bottom:0px">
<br></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px"><font face="arial, helvetica, sans-serif"><br></font></pre></font></span></div></div></div></div></blockquote><div><br></div><div>I'm not terribly familiar with how memory management is done in the GLSL lexer and parser, but I agree this looks suspicious.<br>
<br>I'm also suspicious of the other calls to strdup() in glsl_lexer.ll (in the KEYWORD_WITH_ALT macro, and the handling of the "layout" keyword. It seems like all of these should be using ralloc_strdup(). Otherwise, if an identifier gets lexed but not parsed (which could happen if there's a parse error), the memory will never be freed.<br>
<br>Anyone more familiar with this code want to comment? (Ken, perhaps?)<br></div></div></div></div>