[PATCH 1/2] vsh: cmdComplete: Don't leak buffer for completion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tools/vsh.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 2805574ec6..05de54b5b0 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -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++) {
-- 
2.44.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux