[PATCH 6/6] virbitmaptest: Resolve Coverity errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



test1: Need to check for bitmap before using as well as free it properly
test2: need to check for bitsString2 before using it.
---
 tests/virbitmaptest.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
index db76672..66ffd1b 100644
--- a/tests/virbitmaptest.c
+++ b/tests/virbitmaptest.c
@@ -29,26 +29,33 @@ static int test1(const void *data ATTRIBUTE_UNUSED)
     int size;
     int bit;
     bool result;
+    int ret = -1;
 
     size = 1024;
     bit = 100;
-    bitmap = virBitmapNew(size);
+    if (!(bitmap = virBitmapNew(size)))
+        goto error;
+
     if (virBitmapSetBit(bitmap, bit) < 0)
-        return -1;
+        goto error;
 
     if (virBitmapGetBit(bitmap, bit, &result) < 0)
-        return -1;
+        goto error;
 
     if (!result)
-        return -1;
+        goto error;
 
     if (virBitmapGetBit(bitmap, bit + 1, &result) < 0)
-        return -1;
+        goto error;
 
     if (result)
-        return -1;
+        goto error;
 
-    return 0;
+    ret = 0;
+
+error:
+    virBitmapFree(bitmap);
+    return ret;
 }
 
 static int
@@ -102,7 +109,8 @@ static int test2(const void *data ATTRIBUTE_UNUSED)
     if (virBitmapCountBits(bitmap) != 48)
         goto error;
 
-    bitsString2 = virBitmapFormat(bitmap);
+    if (!(bitsString2 = virBitmapFormat(bitmap)))
+        goto error;
     if (strcmp(bitsString1, bitsString2))
         goto error;
 
-- 
1.7.11.7

--
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]