Blob Blame History Raw
From cc6d53dc895fdf19ffe65d35b9dc2b802edbf2de Mon Sep 17 00:00:00 2001
Message-Id: <cc6d53dc895fdf19ffe65d35b9dc2b802edbf2de@dist-git>
From: John Ferlan <jferlan@redhat.com>
Date: Mon, 15 Sep 2014 15:13:54 -0400
Subject: [PATCH] qemu: Resolve Coverity NEGATIVE_RETURNS

https://bugzilla.redhat.com/show_bug.cgi?id=1141209

Coverity notes that if the virConnectListAllDomains returns a negative
value then the loop at the cleanup label that ends on numDomains will
have issues.

Signed-off-by: John Ferlan <jferlan@redhat.com>
(cherry picked from commit 81a8fc34ad79386deb774f1e234797ae3641584c)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_driver.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3c7f2ba..a2b9901 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1004,9 +1004,11 @@ qemuStateStop(void)
             ret = -1;
 
  cleanup:
-    for (i = 0; i < numDomains; i++)
-        virDomainFree(domains[i]);
-    VIR_FREE(domains);
+    if (domains) {
+        for (i = 0; i < numDomains; i++)
+            virDomainFree(domains[i]);
+        VIR_FREE(domains);
+    }
     VIR_FREE(flags);
     virObjectUnref(conn);
     virObjectUnref(cfg);
-- 
2.1.0