bison and valgrind




I've made some progress and have managed to use bison and flex to write
some simple parsers. The types that they return are complicated data
structures. Before I wrote the parser, the routines I wrote for working
with these data structures were very carefully tested to avoid memory
leaks. One of the things I did to avoid leaks was to use valgrind.

What I'm worried about is that the parser might have a lot of leaks.
The reason I think it is vulnerable to that is that in the actions
I invoke routines that return the various data structures but I don't
know of any logical place to call the routines I use to free those
data structures. That's because I don't know enough about the workings
of the parsers produced by bison and flex.

I haven't actually tested the parser with valgrind. I'll do that tomorrow.
I just consider it extremely likely that it will be leaky.

When I do run it through valgrind, and if I do find the expected leak, then
maybe I can figure out how to modify the parser to plug the leak, and maybe
not.. Assuming I can do that, what I am then worried about is that the place
where I have to modify the parser to plug the leak will be part of the boiler
plate code that bison uses, and therefore is not really accessible as part of
the normal use of bison and flex. In particular, if I modify the .y file, I
will also have to modify by hand the file that bison produces every time I do
so. There are worse fates, but if there is a way to avoid this particular
fate, I'd like to know about it.

So, that's the question: how to deal with memory leaks in parsers generated
by bison and flex?

I'm doing this on an old PC running RedHat 7.1 Linux.
--
Ignorantly,
Allan Adler <ara@xxxxxxxxxxxxxxxxxxxx>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
.



Relevant Pages

  • Csup cvsmode build discussion
    ... lex and yacc files that I would like to discuss. ... I implemented the RCS parser required to operate on RCS files ... I've been compiling the parser and tokenizer with the help of bison ... Now, the base system already have flex, but the flex version in base is heavily ...
    (freebsd-hackers)
  • Re: Csup cvsmode build discussion
    ... lex and yacc files that I would like to discuss. ... I implemented the RCS parser required to operate on RCS files ... I've been compiling the parser and tokenizer with the help of bison ... Now, the base system already have flex, but the flex version in base is heavily ...
    (freebsd-hackers)
  • Re: Flex&Bison: how to write a parser for this grammar?
    ... bison? ... it's better to rely on a parser generator than on hand-written ... a yacc parser will be simpler if the grammar is suitable so ... need for flex start conditions there as I feared there might be. ...
    (comp.programming)
  • Re: bison and valgrind
    ... As I expected the parser is leaky. ... Bison has no interest in the C in your actions, ... An easy way to solve the above problem is to write your own allocator ... I found that there were leaks in the routines ...
    (comp.programming)
  • Re: RosAsm is still broken to this day.
    ... this will never save you from having written an HLL Pre- ... Parser in C, Flex and Bison. ...
    (alt.lang.asm)