[libvirt] [PATCH] tests: Fix commandtest in VPATH build
Eric Blake
eblake at redhat.com
Fri Dec 3 18:20:37 UTC 2010
On 12/03/2010 09:21 AM, Jiri Denemark wrote:
> ---
> tests/commandtest.c | 6 +++++-
> 1 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/tests/commandtest.c b/tests/commandtest.c
> index ace2f33..31adeea 100644
> --- a/tests/commandtest.c
> +++ b/tests/commandtest.c
> @@ -509,9 +509,12 @@ cleanup:
> * Only stdin/out/err open
> */
> static int test15(const void *unused ATTRIBUTE_UNUSED) {
> + char *cwd = NULL;
> virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
>
> - virCommandSetWorkingDirectory(cmd, abs_builddir "/commanddata");
> + if (virAsprintf(&cwd, "%s/commanddata", abs_srcdir) < 0)
> + return -1;
Oops - this needs to call virCommandFree(cmd) before returning.
> + virCommandSetWorkingDirectory(cmd, cwd);
Sweet - I knew it would be worth adding virCommandSetWorkingDirectory,
even when it wasn't in Dan's original implementation.
>
> if (virCommandRun(cmd, NULL) < 0) {
> virErrorPtr err = virGetLastError();
> @@ -519,6 +522,7 @@ static int test15(const void *unused ATTRIBUTE_UNUSED) {
> return -1;
> }
>
> + VIR_FREE(cwd);
Oops - this leaks cwd if you returned 3 lines earlier. You can float
the VIR_FREE(cwd) up to just after the virCommandSetWorkingDirectory
call, since you don't need cwd after that point.
NACK - I'll need to see a leak-free v2 before approving.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20101203/64646cf5/attachment-0001.sig>
More information about the libvir-list
mailing list