From: Peter Krempa Date: Thu, 8 Dec 2022 10:19:23 +0000 (+0100) Subject: virStorageBackendISCSISetAuth: Refactor cleanup X-Git-Tag: v9.1.0-rc1~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbb323fe615dd5390e2c86779a978629b323fa35;p=thirdparty%2Flibvirt.git virStorageBackendISCSISetAuth: Refactor cleanup Automatically free 'conn' and remove the 'cleanup' section and 'ret' variable. 'datatypes.h' contains the declaration of the autoptr cleanup function for virConnect. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c index 968a70158b..e4fa49d05f 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -26,6 +26,7 @@ #include #include +#include "datatypes.h" #include "driver.h" #include "storage_backend_iscsi.h" #include "viralloc.h" @@ -255,8 +256,8 @@ virStorageBackendISCSISetAuth(const char *portal, size_t secret_size; g_autofree char *secret_str = NULL; virStorageAuthDef *authdef = source->auth; - int ret = -1; - virConnectPtr conn = NULL; + int ret = 0; + g_autoptr(virConnect) conn = NULL; VIR_IDENTITY_AUTORESTORE virIdentity *oldident = NULL; if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) @@ -280,7 +281,7 @@ virStorageBackendISCSISetAuth(const char *portal, 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); @@ -299,13 +300,9 @@ virStorageBackendISCSISetAuth(const char *portal, source->devices[0].path, "node.session.auth.password", secret_str) < 0) - goto cleanup; + ret = -1; - ret = 0; - - cleanup: virSecureErase(secret_str, secret_size); - virObjectUnref(conn); return ret; }