]> xenbits.xensource.com Git - libvirt.git/commitdiff
doRemoteOpen: Refactor control flow
authorPeter Krempa <pkrempa@redhat.com>
Wed, 18 May 2022 09:18:54 +0000 (11:18 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 18 May 2022 11:46:30 +0000 (13:46 +0200)
Use a temporary variable 'newconn' to hold the newly opened connection
until we are ready to pass it back instead of the original connection.

This way we can avoid complicated 'error'/'cleanup' sections.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/remote/remote_daemon_dispatch.c

index 39953f46cff2b7e5f2c4e54b4f9ea46d76e7be58..c1f85925a38e429f3ccfe185d4c6c63d07c6a63b 100644 (file)
@@ -1794,7 +1794,7 @@ remoteOpenConn(const char *uri,
                virConnectPtr *conn)
 {
     g_autoptr(virTypedParamList) identparams = NULL;
-    int ret = -1;
+    g_autoptr(virConnect) newconn = NULL;
 
     VIR_DEBUG("Getting secondary uri=%s readonly=%d preserveIdent=%d conn=%p",
               NULLSTR(uri), readonly, preserveIdentity, conn);
@@ -1814,34 +1814,30 @@ remoteOpenConn(const char *uri,
             return -1;
 
         if (!(identparams = virIdentityGetParameters(ident)))
-            goto error;
+            return -1;
     }
 
     VIR_DEBUG("Opening driver %s", uri);
     if (readonly)
-        *conn = virConnectOpenReadOnly(uri);
+        newconn = virConnectOpenReadOnly(uri);
     else
-        *conn = virConnectOpen(uri);
-    if (!*conn)
-        goto error;
-    VIR_DEBUG("Opened driver %p", *conn);
+        newconn = virConnectOpen(uri);
+
+    if (!newconn)
+        return -1;
+
+    VIR_DEBUG("Opened driver %p", newconn);
 
     if (preserveIdentity) {
         if (virConnectSetIdentity(*conn, identparams->par, identparams->npar, 0) < 0)
-            goto error;
+            return -1;
 
         VIR_DEBUG("Forwarded current identity to secondary driver");
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    *conn = g_steal_pointer(&newconn);
 
- error:
-    if (*conn) {
-        g_clear_pointer(conn, virConnectClose);
-    }
-    goto cleanup;
+    return 0;
 }