]> xenbits.xensource.com Git - libvirt.git/commitdiff
vshtabletest: Fix potential memleak
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Dec 2021 09:23:15 +0000 (10:23 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 17 Dec 2021 14:05:42 +0000 (15:05 +0100)
In testVshTableNew() we test whether vshTableNew(NULL) allocates
a table. This is expected to fail (and return NULL), because
passing nothing but NULL to vshTableNew() is viewed as error.
Nevertheless, if vshTableNew() did not fail and returned an
allocated table it would be leaked.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/vshtabletest.c

index 41ceec0a51caf7031732f315929a7c8a935e59bd..2b997753ff311e0bc6dab6f7e6ba225ff49c782f 100644 (file)
@@ -33,7 +33,9 @@
 static int
 testVshTableNew(const void *opaque G_GNUC_UNUSED)
 {
-    if (vshTableNew(NULL)) {
+    g_autoptr(vshTable) table = vshTableNew(NULL);
+
+    if (table) {
         fprintf(stderr, "expected failure when passing null to vshTableNew\n");
         return -1;
     }