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 <pkrempa(a)redhat.com>
---
src/storage/storage_backend_iscsi.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 9f9aa01f05..c5e3130a4f 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <sys/stat.h>
+#include "datatypes.h"
#include "driver.h"
#include "storage_backend_iscsi.h"
#include "viralloc.h"
@@ -254,8 +255,7 @@ virStorageBackendISCSISetAuth(const char *portal,
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)
@@ -279,7 +279,7 @@ virStorageBackendISCSISetAuth(const char *portal,
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
VIR_SECRET_USAGE_TYPE_ISCSI,
&secret_value, &secret_size) < 0)
- goto cleanup;
+ return -1;
/* '\0' terminate the data into a string */
secret_str = g_strndup((char *) secret_value, secret_size);
@@ -296,13 +296,9 @@ virStorageBackendISCSISetAuth(const char *portal,
source->devices[0].path,
"node.session.auth.password",
secret_str) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- virObjectUnref(conn);
- return ret;
+ return 0;
}
static int
--
2.38.1