]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageBackendISCSIDirectSetAuth: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Dec 2022 10:13:53 +0000 (11:13 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 1 Feb 2023 08:16:17 +0000 (09:16 +0100)
Use automatic pointer for 'conn' and remove the 'cleanup' label and
'ret' variable.

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

index 5df54470663031b4269b8878165b1ec5343c9a2d..63225c533ec3f4d129d49cb4777304b8d2a89863 100644 (file)
@@ -91,8 +91,7 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_context *iscsi,
     size_t secret_size;
     g_autofree char *secret_str = NULL;
     virStorageAuthDef *authdef = source->auth;
-    int ret = -1;
-    virConnectPtr conn = NULL;
+    g_autoptr(virConnect) conn = NULL;
     VIR_IDENTITY_AUTORESTORE virIdentity *oldident = NULL;
 
     if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
@@ -104,19 +103,19 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_context *iscsi,
     if (authdef->authType != VIR_STORAGE_AUTH_TYPE_CHAP) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("iscsi-direct pool only supports 'chap' auth type"));
-        return ret;
+        return -1;
     }
 
     if (!(oldident = virIdentityElevateCurrent()))
         return -1;
 
     if (!(conn = virGetConnectSecret()))
-        return ret;
+        return -1;
 
     if (virSecretGetSecretString(conn, &authdef->seclookupdef,
                                  VIR_SECRET_USAGE_TYPE_ISCSI,
                                  &secret_value, &secret_size) < 0)
-        goto cleanup;
+        return -1;
 
     secret_str = g_new0(char, secret_size + 1);
     memcpy(secret_str, secret_value, secret_size);
@@ -125,17 +124,15 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_context *iscsi,
 
     if (iscsi_set_initiator_username_pwd(iscsi,
                                          authdef->username, secret_str) < 0) {
+        virSecureErase(secret_str, secret_size);
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to set credential: %s"),
                        iscsi_get_error(iscsi));
-        goto cleanup;
+        return -1;
     }
-
-    ret = 0;
- cleanup:
     virSecureErase(secret_str, secret_size);
-    virObjectUnref(conn);
-    return ret;
+
+    return 0;
 }
 
 static int