From 5b811a199d2f09043ae4210b1b56908fc9123285 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 1 Mar 2022 17:29:04 +0100 Subject: [PATCH] virsh: cmdDesc: Automatically free memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decrease scope of variables and use automatic freeing. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tools/virsh-domain.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index dcf0f712f6..4d9722f400 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -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; }