From 100052135f2bdafde30d551d8e269e8d1233778d Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 26 Jan 2021 10:23:32 +0100 Subject: [PATCH] vshReadlineParse: Use g_auto*() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of freeing @partial and @buf explicitly, we can use g_auto*() to do that automatically. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- tools/vsh.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index ba6299aae4..9a7ca6776b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -739,6 +739,8 @@ vshCommandFree(vshCmd *cmd) } } +G_DEFINE_AUTOPTR_CLEANUP_FUNC(vshCmd, vshCommandFree); + /** * vshCommandOpt: * @cmd: parsed command line to search @@ -2704,10 +2706,10 @@ vshReadlineParse(const char *text, int state) * initialize those static variables above. On subsequent * calls @state is non zero. */ if (!state) { - vshCmd *partial = NULL; + g_autoptr(vshCmd) partial = NULL; const vshCmdDef *cmd = NULL; const vshCmdOptDef *opt = NULL; - char *buf = g_strdup(rl_line_buffer); + g_autofree char *buf = g_strdup(rl_line_buffer); g_strfreev(list); list = NULL; @@ -2717,8 +2719,6 @@ vshReadlineParse(const char *text, int state) vshCommandStringParse(NULL, buf, &partial); - VIR_FREE(buf); - if (partial) { cmd = partial->def; partial->skipChecks = true; @@ -2759,12 +2759,10 @@ vshReadlineParse(const char *text, int state) (vshCompleterFilter(&completer_list, text) < 0 || virStringListMerge(&list, &completer_list) < 0)) { g_strfreev(completer_list); - vshCommandFree(partial); goto cleanup; } } } - vshCommandFree(partial); } if (list) {