]> xenbits.xensource.com Git - libvirt.git/commitdiff
vsh: Use g_auto(GStrv) to free string list returned by completer callback
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Jan 2021 16:12:50 +0000 (17:12 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Feb 2021 10:51:59 +0000 (11:51 +0100)
This saves us explicit call of g_strfreev() in error path.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
tools/vsh.c

index 3771ad50e9625f72f472a6f15c3b389f73dafffd..bb8b90b08eb59e5cc92f0a62314a17f941d9cd70 100644 (file)
@@ -2778,9 +2778,9 @@ vshReadlineParse(const char *text, int state)
                 list = vshReadlineOptionsGenerator(text, cmd, partial);
 
             if (opt && opt->completer) {
-                char **completer_list = opt->completer(autoCompleteOpaque,
-                                                       partial,
-                                                       opt->completer_flags);
+                g_auto(GStrv) completer_list = opt->completer(autoCompleteOpaque,
+                                                              partial,
+                                                              opt->completer_flags);
 
                 /* Escape completions, if needed (i.e. argument
                  * we are completing wasn't started with a quote
@@ -2805,7 +2805,6 @@ vshReadlineParse(const char *text, int state)
                 if (completer_list &&
                     (vshCompleterFilter(&completer_list, text) < 0 ||
                      virStringListMerge(&list, &completer_list) < 0)) {
-                    g_strfreev(completer_list);
                     goto cleanup;
                 }
             }