Re: Question about token stack

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
Hi Ervin,

> Le 30 août 2020 à 11:44, Ervin Hegedüs <[email protected]> a écrit :
> 
> Hi all,
> 
> and in parser:
> 
> https://github.com/airween/flextest/blob/master/myparser.y#L52
> 
> config_directive_line:
>      T_CONFIG_DIRECTIVE T_CONFIG_DIRECTIVE_ARGUMENT { printf("'%s' '%s'\n", $1, $2); free($1); free($2); }
> 
> This works as well, but I found some interesting thing when I
> analyzed my code with valgrind: the pushed token is still
> reachable when the parser run into an error.
> 
> There is a wrong config: badconf.conf.
> 
> Here is the result:
> 
> valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes ./myparser badconf.conf
> 
> ==564114== 4 bytes in 1 blocks are still reachable in loss record 1 of 4
> ==564114==    at 0x483677F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==564114==    by 0x48EB71A: strdup (strdup.c:42)
> ==564114==    by 0x10B86A: push_sym (mylexer.l:111)
> ==564114==    by 0x109E7F: yylex (mylexer.l:53)
> ==564114==    by 0x10954B: yyparse (myparser.tab.c:1055)
> ==564114==    by 0x10BD38: open_and_parse (mylexer.l:221)
> ==564114==    by 0x10BF98: main (mylexer.l:272)
> 
> 
> How can I avoid this situation? Is that any "best-practice"? How
> can I access to pointers in stack to free them when error
> occurred?

I have not read all in details, but I believe you need to read
about %destructor.

https://www.gnu.org/software/bison/manual/html_node/Destructor-Decl.html

Cheers!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.