]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: Fix virmacmaptest when allocation fails
authorJohn Ferlan <jferlan@redhat.com>
Wed, 7 Dec 2016 13:07:54 +0000 (08:07 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 8 Dec 2016 19:58:31 +0000 (14:58 -0500)
If the allocation fails in DO_TEST_FLUSH_PROLOGUE, then 'mgr == NULL',
but the code continues on - which won't be good. So modify the macro
to cause an immediate failure and jump to a cleanup label.

Found by Coverity as FORWARD_NULL event.

tests/virmacmaptest.c

index 34609ad44a7f97cfee48f8a22288b2cd0b910be4..4daa0488483937cf6fd5db9d9084ae80a30e9506 100644 (file)
@@ -170,8 +170,12 @@ mymain(void)
     } while (0)
 
 #define DO_TEST_FLUSH_PROLOGUE                                      \
-    if (!(mgr = virMacMapNew(NULL)))                                \
-        ret = -1;
+    do {                                                            \
+        if (!(mgr = virMacMapNew(NULL))) {                          \
+            ret = -1;                                               \
+            goto cleanup;                                           \
+        }                                                           \
+    } while (0)
 
 #define DO_TEST_FLUSH(d, ...)                                       \
     do {                                                            \
@@ -226,6 +230,7 @@ mymain(void)
     DO_TEST_FLUSH("dom1", "9e:89:49:99:51:0e", "89:b4:3f:08:88:2c", "54:0b:4c:e2:0a:39");
     DO_TEST_FLUSH("dom1", "bb:88:07:19:51:9d", "b7:f1:1a:40:a2:95", "88:94:39:a3:90:b4");
     DO_TEST_FLUSH_EPILOGUE("complex");
+ cleanup:
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }