Question about token stack
Ervin Hegedüs <[email protected]>
| Newsgroups | gmane.comp.parsers.bison.general |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I could finish the handling of include files - both for explicit
listing and using metacharacters (eg. config*.conf).
You can check that here:
https://github.com/airween/flextest
(Note, this is just an example project...)
I still have a question - as you can see, I've created a function
which push the scanned token to stack, what usen in parser. Eg.:
https://github.com/airween/flextest/blob/master/mylexer.l#L49
<INITIAL>(\s*)Conf[a-zA-Z0-9]+ { push_sym(); ...
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?
In the generated code (myparser.tab.c) I see there is the yyvsp[]
array - but I can access to that. Or em I wrong?
Thanks,
a.