Automatically unref the 'conn' object and remove the 'cleanup' section
and 'ret' variable.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/libxl/libxl_conf.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 54e50a24cf..9f0d5717c7 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1021,10 +1021,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) {
@@ -1033,31 +1032,25 @@ 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);
}
- *srcstr = libxlMakeNetworkDiskSrcStr(src, username, base64secret);
-
- if (!*srcstr)
- goto cleanup;
-
- ret = 0;
+ if (!(*srcstr = libxlMakeNetworkDiskSrcStr(src, username, base64secret)))
+ return -1;
- cleanup:
- virObjectUnref(conn);
- return ret;
+ return 0;
}
int
--
2.38.1