]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxlMakeNetworkDiskSrc: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Dec 2022 11:24:30 +0000 (12:24 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 1 Feb 2023 08:16:17 +0000 (09:16 +0100)
Automatically unref the 'conn' object and remove the 'cleanup' section
and 'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/libxl/libxl_conf.c

index 17ac88063477efa9da8eeb62f05ea83bfbfcfd50..cee9f827f725c2c11c8532ed5677b7b79184cac7 100644 (file)
@@ -1026,10 +1026,9 @@ libxlMakeNetworkDiskSrcStr(virStorageSource *src,
 static int
 libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr)
 {
-    virConnectPtr conn = NULL;
+    g_autoptr(virConnect) conn = NULL;
     g_autofree char *base64secret = NULL;
     char *username = NULL;
-    int ret = -1;
 
     *srcstr = NULL;
     if (src->auth && src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) {
@@ -1038,16 +1037,16 @@ libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr)
         VIR_IDENTITY_AUTORESTORE virIdentity *oldident = virIdentityElevateCurrent();
 
         if (!oldident)
-            goto cleanup;
+            return -1;
 
         username = src->auth->username;
         if (!(conn = virConnectOpen("xen:///system")))
-            goto cleanup;
+            return -1;
 
         if (virSecretGetSecretString(conn, &src->auth->seclookupdef,
                                      VIR_SECRET_USAGE_TYPE_CEPH,
                                      &secret, &secretlen) < 0)
-            goto cleanup;
+            return -1;
 
         /* RBD expects an encoded secret */
         base64secret = g_base64_encode(secret, secretlen);
@@ -1058,13 +1057,9 @@ libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr)
     virSecureEraseString(base64secret);
 
     if (!*srcstr)
-        goto cleanup;
-
-    ret = 0;
+        return -1;
 
- cleanup:
-    virObjectUnref(conn);
-    return ret;
+    return 0;
 }
 
 int