[PATCH 09/14] virsh: cmdSecretGetValue: Use memset instead of VIR_DISPOSE_N

Peter Krempa pkrempa at redhat.com
Mon Feb 1 13:39:01 UTC 2021


Switch the secret value to 'g_autofree' for handling of the memory and
clear it out using memset.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tools/virsh-secret.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 23bbd61698..252219c075 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -302,7 +302,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
 {
     g_autoptr(virshSecret) secret = NULL;
     VIR_AUTODISPOSE_STR base64 = NULL;
-    unsigned char *value;
+    g_autofree unsigned char *value = NULL;
     size_t value_size;
     bool plain = vshCommandOptBool(cmd, "plain");

@@ -314,7 +314,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)

     if (plain) {
         if (fwrite(value, 1, value_size, stdout) != value_size) {
-            VIR_DISPOSE_N(value, value_size);
+            memset(value, 0, value_size);
             vshError(ctl, "failed to write secret");
             return false;
         }
@@ -324,7 +324,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", base64);
     }

-    VIR_DISPOSE_N(value, value_size);
+    memset(value, 0, value_size);
     return true;
 }

-- 
2.29.2




More information about the libvir-list mailing list