]> xenbits.xensource.com Git - libvirt.git/commitdiff
vsh: cmdComplete: Don't leak buffer for completion
authorPeter Krempa <pkrempa@redhat.com>
Thu, 25 Apr 2024 08:05:42 +0000 (10:05 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 25 Apr 2024 12:13:19 +0000 (14:13 +0200)
The buffer which we assign to the 'rl_line_buffer' variable of readline
would be overwritten and thus leaked on multiple invocations of
cmdComplete in one session.

Free/clear it after it's used.

Hitting this leak was until recenly possible only in non-interactive
batch mode and recently also in interactive mode as 'complete' can be
used multiple times now interactively.

Fixes: a0e1ada63c0afdc2af3b9405cbf637d8bd28700c
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/vsh.c

index 2805574ec63f228bfad07ed1803d354e5487ea77..05de54b5b0fd7f0bf7ac9941bee29f79d510607c 100644 (file)
@@ -3439,7 +3439,10 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
      * In our case it's at the end of the whole line. */
     rl_point = strlen(rl_line_buffer);
 
-    if (!(matches = vshReadlineCompletion(arg, 0, 0)))
+    matches = vshReadlineCompletion(arg, 0, 0);
+    g_clear_pointer(&rl_line_buffer, g_free);
+
+    if (!matches)
         return false;
 
     for (iter = matches; *iter; iter++) {