Automatically clean the secret object and get rid of the cleanup label
and 'ret' valiable.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
tools/virsh-secret.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 58c9a54af6..7067d13353 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -240,29 +240,23 @@ static const vshCmdOptDef opts_secret_get_value[] = {
static bool
cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
{
- virSecretPtr secret;
+ g_autoptr(virshSecret) secret = NULL;
VIR_AUTODISPOSE_STR base64 = NULL;
unsigned char *value;
size_t value_size;
- bool ret = false;
- secret = virshCommandOptSecret(ctl, cmd, NULL);
- if (secret == NULL)
+ if (!(secret = virshCommandOptSecret(ctl, cmd, NULL)))
return false;
- value = virSecretGetValue(secret, &value_size, 0);
- if (value == NULL)
- goto cleanup;
+ if (!(value = virSecretGetValue(secret, &value_size, 0)))
+ return false;
base64 = g_base64_encode(value, value_size);
vshPrint(ctl, "%s", base64);
- ret = true;
- cleanup:
VIR_DISPOSE_N(value, value_size);
- virshSecretFree(secret);
- return ret;
+ return true;
}
/*
--
2.24.1