]> xenbits.xensource.com Git - libvirt.git/commitdiff
remoteConnectOpen: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Sep 2022 16:00:12 +0000 (18:00 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 13 Sep 2022 08:50:02 +0000 (10:50 +0200)
Use automatic memory freeing for 'driver' and return error right away to
avoid the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/remote/remote_driver.c

index 0ca365c4cc603d811a70809af15ea6ae6637d9f0..b670284211c488111ffb4efb9cf1c650a568409a 100644 (file)
@@ -1228,23 +1228,20 @@ remoteConnectOpen(virConnectPtr conn,
     struct private_data *priv;
     int ret = VIR_DRV_OPEN_ERROR;
     unsigned int rflags = 0;
-    char *driver = NULL;
+    g_autofree char *driver = NULL;
     remoteDriverTransport transport;
 
     if (conn->uri) {
         if (remoteSplitURIScheme(conn->uri, &driver, &transport) < 0)
-            goto cleanup;
+            return VIR_DRV_OPEN_ERROR;
     } else {
         /* No URI, then must be probing so use UNIX socket */
         transport = REMOTE_DRIVER_TRANSPORT_UNIX;
     }
 
-
     if (inside_daemon) {
-        if (!conn->uri) {
-            ret = VIR_DRV_OPEN_DECLINED;
-            goto cleanup;
-        }
+        if (!conn->uri)
+            return VIR_DRV_OPEN_DECLINED;
 
         /* If there's a driver registered we must defer to that.
          * If there isn't a driver, we must connect in "direct"
@@ -1254,15 +1251,12 @@ remoteConnectOpen(virConnectPtr conn,
          * host */
         if (!conn->uri->server &&
             virHasDriverForURIScheme(driver) &&
-            !virURICheckUnixSocket(conn->uri)) {
-            ret = VIR_DRV_OPEN_DECLINED;
-            goto cleanup;
-        }
+            !virURICheckUnixSocket(conn->uri))
+            return VIR_DRV_OPEN_DECLINED;
     }
 
     if (!(priv = remoteAllocPrivateData()))
-        goto cleanup;
-
+        return VIR_DRV_OPEN_ERROR;
 
     remoteGetURIDaemonInfo(conn->uri, transport, &rflags);
     if (flags & VIR_CONNECT_RO)
@@ -1278,8 +1272,6 @@ remoteConnectOpen(virConnectPtr conn,
         remoteDriverUnlock(priv);
     }
 
- cleanup:
-    VIR_FREE(driver);
     return ret;
 }