]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Alter error path cleanup for qemuDomainAttachChrDevice
authorJohn Ferlan <jferlan@redhat.com>
Thu, 14 Jul 2016 21:55:05 +0000 (17:55 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 19 Jul 2016 11:13:09 +0000 (07:13 -0400)
Based on recent review comment - rather than have a spate of goto failxxxx,
change to a boolean based model. Ensures that the original error can be
preserved and cleanup is a bit more orderly if more objects are added.

src/qemu/qemu_hotplug.c

index 2079231b56e01f51005af020c96fdf650874abf1..6839be24d82be07601038e5608102ec4421a82db 100644 (file)
@@ -1508,9 +1508,11 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
 {
     int ret = -1, rc;
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    virErrorPtr orig_err;
     virDomainDefPtr vmdef = vm->def;
     char *devstr = NULL;
     char *charAlias = NULL;
+    bool chardevAttached = false;
     bool need_release = false;
 
     if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
@@ -1536,10 +1538,11 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
 
     qemuDomainObjEnterMonitor(driver, vm);
     if (qemuMonitorAttachCharDev(priv->mon, charAlias, &chr->source) < 0)
-        goto failchardev;
+        goto exit_monitor;
+    chardevAttached = true;
 
     if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
-        goto failadddev;
+        goto exit_monitor;
 
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto audit;
@@ -1557,10 +1560,16 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
     VIR_FREE(devstr);
     return ret;
 
- failadddev:
+ exit_monitor:
+    orig_err = virSaveLastError();
     /* detach associated chardev on error */
-    qemuMonitorDetachCharDev(priv->mon, charAlias);
- failchardev:
+    if (chardevAttached)
+        qemuMonitorDetachCharDev(priv->mon, charAlias);
+    if (orig_err) {
+        virSetError(orig_err);
+        virFreeError(orig_err);
+    }
+
     ignore_value(qemuDomainObjExitMonitor(driver, vm));
     goto audit;
 }