]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: avoid dereferencing a NULL pointer
authorAlex Jia <ajia@redhat.com>
Wed, 21 Sep 2011 19:02:44 +0000 (03:02 +0800)
committerEric Blake <eblake@redhat.com>
Wed, 21 Sep 2011 21:25:52 +0000 (15:25 -0600)
* src/qemu/qemu_process.c: Taking if (qemuDomainObjEndJob(driver, obj) == 0)
  true branch then 'obj' is NULL, virDomainObjIsActive(obj) and
  virDomainObjUnref(obj) will dereference NULL pointer.

Signed-off-by: Alex Jia <ajia@redhat.com>
src/qemu/qemu_process.c

index bd49b211d31194dcaa7ee2bbd7bfb2d1b612b62a..9fdf846a6030fa4d864f70356521fa592790a374 100644 (file)
@@ -2661,22 +2661,24 @@ error:
     if (qemuDomainObjEndJob(driver, obj) == 0)
         obj = NULL;
 
-    if (!virDomainObjIsActive(obj)) {
-        if (virDomainObjUnref(obj) > 0)
-            virDomainObjUnlock(obj);
-        qemuDriverUnlock(driver);
-        return;
-    }
+    if (obj) {
+        if (!virDomainObjIsActive(obj)) {
+            if (virDomainObjUnref(obj) > 0)
+                virDomainObjUnlock(obj);
+            qemuDriverUnlock(driver);
+            return;
+        }
 
-    if (virDomainObjUnref(obj) > 0) {
-        /* We can't get the monitor back, so must kill the VM
-         * to remove danger of it ending up running twice if
-         * user tries to start it again later */
-        qemuProcessStop(driver, obj, 0, VIR_DOMAIN_SHUTOFF_FAILED);
-        if (!obj->persistent)
-            virDomainRemoveInactive(&driver->domains, obj);
-        else
-            virDomainObjUnlock(obj);
+        if (virDomainObjUnref(obj) > 0) {
+            /* We can't get the monitor back, so must kill the VM
+            * to remove danger of it ending up running twice if
+            * user tries to start it again later */
+            qemuProcessStop(driver, obj, 0, VIR_DOMAIN_SHUTOFF_FAILED);
+            if (!obj->persistent)
+                virDomainRemoveInactive(&driver->domains, obj);
+            else
+                virDomainObjUnlock(obj);
+        }
     }
     qemuDriverUnlock(driver);