]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: cmdDesc: Automatically free memory
authorPeter Krempa <pkrempa@redhat.com>
Tue, 1 Mar 2022 16:29:04 +0000 (17:29 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 3 Mar 2022 10:06:57 +0000 (11:06 +0100)
Decrease scope of variables and use automatic freeing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-domain.c

index dcf0f712f66d711e64d7ab6d2dd36539e682a1cd..4d9722f4002548f02791bb7d0ec74850db4cf0f6 100644 (file)
@@ -8333,9 +8333,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
 
     int state;
     int type;
-    char *desc = NULL;
-    char *desc_edited = NULL;
-    char *tmpstr;
+    g_autofree char *desc = NULL;
     const vshCmdOpt *opt = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     bool ret = false;
@@ -8379,6 +8377,8 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
 
         if (edit) {
             g_autoptr(vshTempFile) tmp = NULL;
+            g_autofree char *desc_edited = NULL;
+            char *tmpstr;
 
             /* Create and open the temporary file. */
             if (!(tmp = vshEditWriteToTempFile(ctl, desc)))
@@ -8438,8 +8438,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
 
     ret = true;
  cleanup:
-    VIR_FREE(desc_edited);
-    VIR_FREE(desc);
     return ret;
 }