Re: bison and valgrind
- From: "Rob Thorpe" <rthorpe@xxxxxxxxxxxxxxxxx>
- Date: 30 Mar 2007 02:47:13 -0700
On Mar 30, 5:24 am, Allan Adler <a...@xxxxxxxxxxxxxxxxxxxx> wrote:
Allan Adler <a...@xxxxxxxxxxxxxxxxxxxx> writes:
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.
I did it. As I expected the parser is leaky. Let's call the data type a gleep.
When the action says {$$ = cat_gleep($1,$2);}
thereby causing a new gleep to be allocated, I found that bison doesn't
complain if I change it to something like:
{$$ = cat_gleep($1,$2);
free_gleep(&$1);
free_gleep(&$2);
}
Yes. Bison has no interest in the C in your actions, you can write
leaks in that to your hearts content.
An easy way to solve the above problem is to write your own allocator
for your parser. What you do is to allocate say 16kb for parser
info. You use this to build the tree then you can write a routine
that frees all memory associated with your special allocator when you
have finished with the tree.
GC is the best way though.
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.
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).
Flex uses one buffer for the characters taken from the stream it's
parsing. I think it expands this buffer as needed, to the length of
the longest token, and never shrinks it. This isn't really a leak,
but valgrind will consider it one.
.
- Follow-Ups:
- Re: bison and valgrind
- From: Allan Adler
- Re: bison and valgrind
- References:
- bison and valgrind
- From: Allan Adler
- Re: bison and valgrind
- From: Allan Adler
- bison and valgrind
- Prev by Date: Re: computing the moment of inertia
- Next by Date: Re: computing the moment of inertia
- Previous by thread: Re: bison and valgrind
- Next by thread: Re: bison and valgrind
- Index(es):
Relevant Pages
|