Re: bison and valgrind



Allan Adler wrote:

I found that bison
doesn't complain if I change it to something like:
{$$ = cat_gleep($1,$2);
free_gleep(&$1);
free_gleep(&$2);
}

Of course, not. Bison is a parser generator. It has no interest in
the semantic content of your parse actions. You could do
(for i = 0; i < 10000; i++)
malloc(1000);
in there if you wanted -- it's no part of Bison's job to prevent, or
even help diagnose, that.

If you want automatic storage management (which I think you /should/
want) then you know where to find it ;-)


That probably means that I do have a little bit of control over leaks.

It would be fairer to say that you can choose whether to introduce
leaks or not. Nothing to do with Bison.


When I ran valgrind, I found that there were leaks in the routines
yy_flex_alloc and yy_create_buffer. I'm less certain about how to deal
with these, since it appears that they come from the boiler plate of
flex (I don't really know for sure).

I find it hard to believe that there's a leak in Flex as the term is
normally understood. It may well be that there's a one-off allocation
that is never released (which is normal and unsurprising, even though
it may be unacceptable for your application). But if Flex-generated
scanners leak a certain amount of memory on every call (or in some
other pattern which means that Flex can leak an unbounded amount of
memory over a program's lifetime) then I'd be more than a little
surprised. And it would be a bug well-worth fixing, so I don't think
you'd have difficulty persuading the Flex maintainers to adopt a fix.

-- chris
.



Relevant Pages

  • Re: Memory leak in flex generated file
    ... >I am using flex and bison to parse HTTP headers. ... allocations will be global and valgrind might be considering them to ... be a leak. ... had a number of ways to leak memory. ...
    (comp.compilers)
  • 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)
  • 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?
    ... the format defines ... bison? ... If you have to do it, you can force the issue by using flex states (I ... Again there is a count but here I would not bother to try to parse ...
    (comp.programming)
  • Re: levcomp kicking my butt
    ... new *.l and *.y files using lex and yacc. ... Install flex and bison. ...
    (rec.games.roguelike.nethack)