2011/4/29 Eric Blake <eblake(a)redhat.com>:
On 04/29/2011 11:48 AM, Matthias Bolte wrote:
>> +++ b/tests/testutils.c
>> @@ -478,7 +478,6 @@ int virtTestMain(int argc,
>> int (*func)(void))
>> {
>> int ret;
>> - char cwd[PATH_MAX];
>> #if TEST_OOM
>> int approxAlloc = 0;
>> int n;
>> @@ -491,7 +490,7 @@ int virtTestMain(int argc,
>>
>> abs_srcdir = getenv("abs_srcdir");
>> if (!abs_srcdir)
>> - abs_srcdir = getcwd(cwd, sizeof(cwd));
>> + abs_srcdir = getcwd(NULL, 0);
>> if (!abs_srcdir)
>> exit(EXIT_AM_HARDFAIL);
>
> Now you have created a memory leak (not a critical one, that's true),
> because abs_srcdir can be malloc'ed and you missed to free it.
It's technically only a leak if someone overwrites abs_srcdir with
different contents without freeing it first, since there is a global
variable that still tracks the pointer through the point of program
exit(). Valgrind reports this type of open-ended allocation as "still
reachable", rather than "definitely lost".
I know, but I like valgrind clean software :)
But, to make valgrind even quieter, yes, I can fix things up to free
the
memory if it was not read from getenv and before returning from
virtTestMain.
Thanks.
>
> ACK, with that memory leak fixed.
Pushed with this addition:
diff --git i/tests/testutils.c w/tests/testutils.c
index 91035a2..ae73530 100644
--- i/tests/testutils.c
+++ w/tests/testutils.c
@@ -478,6 +478,7 @@ int virtTestMain(int argc,
int (*func)(void))
{
int ret;
+ bool abs_srcdir_cleanup = falseb;
As I saw this line, I hoped you didn't push it with that typo... and
you didn't :)
Now I'll go and rebase my stack usage cleanup patch.
Matthias