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>:
> * bootstrap.conf (gnulib_modules): Add getcwd-lgpl.
> * tests/commandtest.c (checkoutput): Drop unused cwd.
> * tests/commandhelper.c (main): Let getcwd malloc.
> * tests/testutils.c (virTestMain): Likewise.
> * tools/virsh.c (cmdPwd): Likewise.
> (virshCmds): Expose cmdPwd and cmdCd on mingw.
> ---
>
>> Oh, and now that gnulib getcwd-lgpl exists, we could use it
>> to fix our uses of getcwd(NULL,0), followup coming later.
>
> Âbootstrap.conf    Â|  Â1 +
> Âtests/commandhelper.c | Â Â7 ++++---
> Âtests/commandtest.c  |  Â4 ----
> Âtests/testutils.c   |  Â3 +--
> Âtools/virsh.c     |  34 ++++++++--------------------------
> Â5 files changed, 14 insertions(+), 35 deletions(-)


> diff --git a/tests/testutils.c b/tests/testutils.c
> index 456a735..91035a2 100644
> --- a/tests/testutils.c
> +++ 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.

ACK, with that memory leak fixed.

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]