help-bison
[Top][All Lists]
Advanced

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

Re: Different behaviour with string and number tokens ?


From: Arno Wilhelm
Subject: Re: Different behaviour with string and number tokens ?
Date: Tue, 18 Apr 2006 10:46:05 +0200
User-agent: Mozilla Thunderbird 1.0.7-1.1.fc3 (X11/20050929)

You might want to post a question about cleaning up the strings, to see if you get a reply from some of those using C. Bison has a feature %destructor, that can be used to clean up the stuff in the case of errors. In other case, it must be cleaned up in the actions, I think.

That's a good point. I used strdup() in the flex file:
{WORD}         { yylval.str = strdup( yytext ); return WORD; }

But I get a memory leak even when I free the the in the bison file like this:
WORD   EQUAL         WORD   { $$ = !strncmp( $1, $3, 128 ); free( yylval.str ); 
}

I do not get an error message when compiling but valgrind shows me a leak in 
the strdup() function:

> valgrind --leak-check=full rules
...
...
==935== 3 bytes in 1 blocks are definitely lost in loss record 2 of 3
==935==    at 0x401B46D: malloc (vg_replace_malloc.c:149)
==935==    by 0x40D1B9F: strdup (in /lib/tls/libc-2.3.6.so)
==935==    by 0x8048976: yylex (in /RulezParser/flex_bison_test/rules)
==935==    by 0x804990E: yyparse (in /RulezParser/flex_bison_test/rules)
==935==    by 0x804A498: main (in /RulezParser/flex_bison_test/rules)
...

Guess I search the archives and consult the manual before I post a question 
about this issue -
except somebody here on this list can give me a hint ;-)



thanks,
arno




reply via email to

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