[PATCH v2 3/9] virsh: secret: Refactor cleanup in cmdSecretGetValue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Automatically clean the secret object and get rid of the cleanup label
and 'ret' valiable.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 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





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux