Using alloca in function parameters buggy or works ???
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Thu Sep 16 15:41:00 GMT 2004
I'm looking over some memory leaks in gcc and I'm seeing lots of funny
uses of concat like this from gcc.c:is_directory()
strcmp (path,
concat (dir_separator_str, "lib", dir_separator_str, ".", NULL))
It's pretty clear this memory allocation never gets free'd. I'd like
to replace stuff like this with ACONCAT from libiberty which uses
alloca and thus doesn't leak.
Normally people don't like alloca I assume because if the backup
libiberty C_alloca is used (which uses malloc underneath the hood),
sometimes stuff isn't free'd because we don't call alloca(0) anywhere.
Then memory use balloons in some edge cases.
However we're already leaking here so if it was a "balloon" case we'd
already know about it. :-)
I'd like to make as little code change as possible for these cases,
which means putting the ACONCAT use (and thus a call to alloca) right
in there as a function call parameter.
My question is that I seem to recall passing the result of alloca
immediately as a function parameter was buggy at some point in GCC.
Using such a version might trigger a bootstrap failure if that buggy
GCC is used in stage1.
So I'm wondering:
1. Was this bug in any released version of GCC that we care about?
2. Does my example above trigger the bug?
3. Any simple workaround? (Other than don't do that.)
Thanks,
--Kaveh
--
Kaveh R. Ghazi ghazi@caip.rutgers.edu
More information about the Gcc
mailing list