From c655601d696c8093a75a2f15f212a49051b7238e Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 8 Dec 2022 12:24:30 +0100 Subject: [PATCH] libxlMakeNetworkDiskSrc: Refactor cleanup Automatically unref the 'conn' object and remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/libxl/libxl_conf.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 17ac880634..cee9f827f7 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -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; + return -1; - ret = 0; - - cleanup: - virObjectUnref(conn); - return ret; + return 0; } int