fix memory leak in gengtype

Dimitrios Apostolou jimis@gmx.net
Thu Apr 21 03:03:00 GMT 2011


On Wed, 20 Apr 2011, Jeff Law wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 04/20/11 15:08, Dimitrios Apostolou wrote:
>> Hello list,
>>
>> while trying to build gcc-4.6.0 on my sparcstation, I got gengtype OOM
>> killed. That's when I noticed that its RAM usage peaks at 150MB, which
>> is a bit excessive for parsing a ~500K text file.
>>
>> The attached patch fixes the leak and gengtype now uses a peak of 4MB
>> heap. Hopefully I don't do something wrong, since it took me a while to
>> understand those obstacks...
> The code in question creates an obstack, allocates (and grows) a single
> object on the obstack, then frees the object.  This leaks the underlying
> obstack structure itself and potentially any chunks that were too small
> to hold the object.

Plus a whole page which is preallocated by the obstack, if I understand 
correctly. As a result, for each word in the text file we consume 4KB, 
which are never freed.

>
> It turns out there's a similar leak in gengtype.c which is fixed in the
> same way.
>

Nice, thanks for looking deeper into this, I just stopped when memory 
utilisation seemed ok.

> A quick valgrind test shows that prior to your change gengtype leaked
> roughly 200M, after your change it leaks about 1.3M and after fixing
> gengtype it leaks a little under 300k.
>
> I'll run those changes through the usual tests and check in the changes
> assuming they pass those tests.
>
> Thanks for the patch!
>
>>
>> P.S. I was trying to test gcc on a rare arch (sparc-unknown-linux-gnu)
>> but unfortunately the sparcstation crashed and burned after this, so I
>> can't continue the build and report back :-(
> :(  My old PA box has similar problems, though it merely overheats
> before a bootstrap can complete, so in theory I could coax it to finish
> a bootstrap.   Luckily others (particularly John) have stepped in over
> the last decade and taken excellent care of the PA port.

If by PA you mean PA-RISC, I remember when I had access to a Visualize 
C200 with gentoo on. I loved the machine, but it had an important issue: 
it was absolutely random if it would power up, when pressing the power 
button. But as long as we never turned it off, it worked ok :-)


Dimitris



More information about the Gcc-patches mailing list