]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vshReadlineParse: Use g_auto*()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Jan 2021 09:23:32 +0000 (10:23 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Jan 2021 15:46:41 +0000 (16:46 +0100)
Instead of freeing @partial and @buf explicitly, we can use
g_auto*() to do that automatically.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/vsh.c

index ba6299aae43bdfb0fa34a5901a85069b33e41c43..9a7ca6776b15d02c81f7d9466f2a9e00c803419f 100644 (file)
@@ -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) {