[libvirt] [PATCH 4/4] tests: fix some resource leaks

Pavel Hrdina posted 4 patches 8 years, 11 months ago
[libvirt] [PATCH 4/4] tests: fix some resource leaks
Posted by Pavel Hrdina 8 years, 11 months ago
Found by running valgrind for these tests.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 tests/commandtest.c    | 3 +++
 tests/domaincapstest.c | 2 ++
 tests/fchosttest.c     | 2 ++
 tests/vircgroupmock.c  | 2 ++
 4 files changed, 9 insertions(+)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index 80f10f88fc..1f6f16bcde 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -1093,6 +1093,9 @@ static int test25(const void *unused ATTRIBUTE_UNUSED)
         virCommandPtr cmd = virCommandNew("some/nonexistent/binary");
 
         rv = virCommandExec(cmd);
+
+        virCommandFree(cmd);
+
         if (safewrite(pipeFD[1], &rv, sizeof(rv)) < 0)
             fprintf(stderr, "Unable to write to pipe\n");
         _exit(EXIT_FAILURE);
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index f871197c25..b76332ce94 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -563,6 +563,8 @@ mymain(void)
     DO_TEST_BHYVE("fbuf", "/usr/sbin/bhyve", &bhyve_caps, VIR_DOMAIN_VIRT_BHYVE);
 #endif /* WITH_BHYVE */
 
+    virObjectUnref(cfg);
+
     return ret;
 }
 
diff --git a/tests/fchosttest.c b/tests/fchosttest.c
index ac4e92910d..3ee1912926 100644
--- a/tests/fchosttest.c
+++ b/tests/fchosttest.c
@@ -315,6 +315,7 @@ manageVHBAByStoragePool(const void *data)
         ignore_value(virStoragePoolDestroy(pool));
         goto cleanup;
     }
+    virNodeDeviceFree(dev);
 
     if (virStoragePoolDestroy(pool) < 0)
         goto cleanup;
@@ -322,6 +323,7 @@ manageVHBAByStoragePool(const void *data)
     if ((dev = virNodeDeviceLookupByName(conn, expect_hostname))) {
         VIR_DEBUG("Found expected_hostname '%s' after destroy",
                   expect_hostname);
+        virNodeDeviceFree(dev);
         goto cleanup;
     }
 
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index ce6fd46266..9eb989ad7e 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -429,8 +429,10 @@ static void init_sysfs(void)
             abort();                                                   \
         if (make_controller(path, 0755) < 0) {                         \
             fprintf(stderr, "Cannot initialize %s\n", path);           \
+            free(path);                                                \
             abort();                                                   \
         }                                                              \
+        free(path);                                                    \
     } while (0)
 
     MAKE_CONTROLLER("cpu");
-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/4] tests: fix some resource leaks
Posted by Ján Tomko 8 years, 11 months ago
On Mon, Apr 10, 2017 at 09:54:00AM +0200, Pavel Hrdina wrote:
>Found by running valgrind for these tests.
>
>Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>---
> tests/commandtest.c    | 3 +++
> tests/domaincapstest.c | 2 ++
> tests/fchosttest.c     | 2 ++
> tests/vircgroupmock.c  | 2 ++
> 4 files changed, 9 insertions(+)
>
>diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
>index f871197c25..b76332ce94 100644
>--- a/tests/domaincapstest.c
>+++ b/tests/domaincapstest.c
>@@ -563,6 +563,8 @@ mymain(void)
>     DO_TEST_BHYVE("fbuf", "/usr/sbin/bhyve", &bhyve_caps, VIR_DOMAIN_VIRT_BHYVE);
> #endif /* WITH_BHYVE */
>
>+    virObjectUnref(cfg);
>+
>     return ret;
> }
>

The cfg variable is defined inside an #if WITH_QEMU block, so the unref
should be inside one too.

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