Re: [PATCH 2/2] build: fix getcwd portability problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/4/29 Eric Blake <eblake@xxxxxxxxxx>:
> 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]