Instead of freeing @partial and @buf explicitly, we can use g_auto*() to do that automatically. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- 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) { -- 2.26.2