help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to free yylval


From: cwhite
Subject: Re: how to free yylval
Date: Mon, 7 Jan 2008 22:05:30 -0800 (PST)



Hans Aberg wrote:
> 
> On 7 Jan 2008, at 07:20, cwhite wrote:
> 
>> I use
>>
>> yylval.string_type = strdup(yytext);
>>
>> in my flex file but it seems that this is wasteful and it may cause  
>> memory
>> leaks. I thought that yytext gets replaced everytime the lexer is  
>> called so
>> how is this wasteful? How do I free yylval so that those don't happen?
>> Perhaps there is an alternative to strdup, I'd like to know what  
>> that is.
> 
> See 'man strdup'; memory must be freed using 'free'. Done say in the  
> actions, or using %destructor to do it during error recovers (see  
> Bison manual).
> 
>    Hans Aberg
> 
> _______________________________________________
> address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
> 
> 

So the solution is just 

%destructor                     { free($$); } IDENTIFIER STRING_CONSTANT

and 

free(yylval.string_type); 

Thanks!

-- 
View this message in context: 
http://www.nabble.com/how-to-free-yylval-tp14659563p14683202.html
Sent from the Gnu - Bison - Help mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]