[libvirt] [PATCH 2/4] tests: Call virCommandFree() in cleanup section

Ján Tomko jtomko at redhat.com
Fri Jul 26 14:35:53 UTC 2019


On Fri, Jul 26, 2019 at 09:42:44AM -0400, Stefan Berger wrote:
>Fix a potential memory leak by calling virCommandFree() in the cleanup
>section.
>
>Signed-off-by: Stefan Berger <stefanb at linux.ibm.com>
>---
> tests/commandtest.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
>diff --git a/tests/commandtest.c b/tests/commandtest.c
>index 991c0572b0..dfd15a2079 100644
>--- a/tests/commandtest.c
>+++ b/tests/commandtest.c
>@@ -1219,8 +1219,6 @@ static int test27(const void *unused ATTRIBUTE_UNUSED)
>         goto cleanup;
>     }
>
>-    virCommandFree(cmd);
>-
>     if (!outactual || !erractual)
>         goto cleanup;
>
>@@ -1236,6 +1234,7 @@ static int test27(const void *unused ATTRIBUTE_UNUSED)
>     ret = 0;
>
>  cleanup:
>+    virCommandFree(cmd);
>     VIR_FORCE_CLOSE(pipe1[0]);
>     VIR_FORCE_CLOSE(pipe2[0]);
>     VIR_FORCE_CLOSE(pipe1[1]);

We have the VIR_AUTO* macros you can use to get the compiler to free it
automatically when it goes out of scope. Just declare the variable as:

VIR_AUTOPTR(virCommand) cmd = NULL;

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190726/3d16fc2b/attachment-0001.sig>


More information about the libvir-list mailing list