]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_process: graphics: ref driver config only in function where it is used
authorPavel Hrdina <phrdina@redhat.com>
Sat, 13 Aug 2016 18:54:58 +0000 (20:54 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 17 Aug 2016 08:04:47 +0000 (10:04 +0200)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com
src/qemu/qemu_process.c

index 3ade190c372e28d913cd2af8ff4e8e66717738f9..a8302c5d84c5722abd4c34f2e2fd2e3b18654c11 100644 (file)
@@ -3547,14 +3547,15 @@ qemuProcessVNCAllocatePorts(virQEMUDriverPtr driver,
 
 static int
 qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
-                              virQEMUDriverConfigPtr cfg,
                               virDomainGraphicsDefPtr graphics,
                               bool allocate)
 {
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     unsigned short port = 0;
     unsigned short tlsPort;
     size_t i;
     int defaultMode = graphics->data.spice.defaultMode;
+    int ret = -1;
 
     bool needTLSPort = false;
     bool needPort = false;
@@ -3600,12 +3601,13 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
         if (needTLSPort || graphics->data.spice.tlsPort == -1)
             graphics->data.spice.tlsPort = 5902;
 
-        return 0;
+        ret = 0;
+        goto cleanup;
     }
 
     if (needPort || graphics->data.spice.port == -1) {
         if (virPortAllocatorAcquire(driver->remotePorts, &port) < 0)
-            goto error;
+            goto cleanup;
 
         graphics->data.spice.port = port;
 
@@ -3618,11 +3620,11 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Auto allocation of spice TLS port requested "
                              "but spice TLS is disabled in qemu.conf"));
-            goto error;
+            goto cleanup;
         }
 
         if (virPortAllocatorAcquire(driver->remotePorts, &tlsPort) < 0)
-            goto error;
+            goto cleanup;
 
         graphics->data.spice.tlsPort = tlsPort;
 
@@ -3630,11 +3632,12 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
             graphics->data.spice.tlsPortReserved = true;
     }
 
-    return 0;
+    ret = 0;
 
error:
cleanup:
     virPortAllocatorRelease(driver->remotePorts, port);
-    return -1;
+    virObjectUnref(cfg);
+    return ret;
 }
 
 
@@ -4072,15 +4075,17 @@ qemuProcessGraphicsSetupNetworkAddress(virDomainGraphicsListenDefPtr glisten,
 
 
 static int
-qemuProcessGraphicsSetupListen(virQEMUDriverConfigPtr cfg,
+qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
                                virDomainGraphicsDefPtr graphics,
                                virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     const char *type = virDomainGraphicsTypeToString(graphics->type);
     char *listenAddr = NULL;
     bool useSocket = false;
     size_t i;
+    int ret = -1;
 
     switch (graphics->type) {
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
@@ -4113,12 +4118,12 @@ qemuProcessGraphicsSetupListen(virQEMUDriverConfigPtr cfg,
                     memset(glisten, 0, sizeof(virDomainGraphicsListenDef));
                     if (virAsprintf(&glisten->socket, "%s/%s.sock",
                                     priv->libDir, type) < 0)
-                        return -1;
+                        goto cleanup;
                     glisten->fromConfig = true;
                     glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET;
                 } else if (listenAddr) {
                     if (VIR_STRDUP(glisten->address, listenAddr) < 0)
-                        return -1;
+                        goto cleanup;
                     glisten->fromConfig = true;
                 }
             }
@@ -4130,14 +4135,14 @@ qemuProcessGraphicsSetupListen(virQEMUDriverConfigPtr cfg,
 
             if (qemuProcessGraphicsSetupNetworkAddress(glisten,
                                                        listenAddr) < 0)
-                return -1;
+                goto cleanup;
             break;
 
         case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
             if (!glisten->socket) {
                 if (virAsprintf(&glisten->socket, "%s/%s.sock",
                                 priv->libDir, type) < 0)
-                    return -1;
+                    goto cleanup;
                 glisten->autoGenerated = true;
             }
             break;
@@ -4148,7 +4153,11 @@ qemuProcessGraphicsSetupListen(virQEMUDriverConfigPtr cfg,
         }
     }
 
-    return 0;
+    ret = 0;
+
+ cleanup:
+    virObjectUnref(cfg);
+    return ret;
 }
 
 
@@ -4157,7 +4166,6 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
                          virDomainObjPtr vm,
                          unsigned int flags)
 {
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     bool allocate = !(flags & VIR_QEMU_PROCESS_START_PRETEND);
     size_t i;
     int ret = -1;
@@ -4178,8 +4186,7 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
                 break;
 
             case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
-                if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics,
-                                                  allocate) < 0)
+                if (qemuProcessSPICEAllocatePorts(driver, graphics, allocate) < 0)
                     goto cleanup;
                 break;
 
@@ -4191,14 +4198,13 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
             }
         }
 
-        if (qemuProcessGraphicsSetupListen(cfg, graphics, vm) < 0)
+        if (qemuProcessGraphicsSetupListen(driver, graphics, vm) < 0)
             goto cleanup;
     }
 
     ret = 0;
 
  cleanup:
-    virObjectUnref(cfg);
     return ret;
 }