]> xenbits.xensource.com Git - libvirt.git/commitdiff
vshReadlineInit: Initialize only once
authorPeter Krempa <pkrempa@redhat.com>
Thu, 25 Apr 2024 08:15:53 +0000 (10:15 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 25 Apr 2024 12:13:19 +0000 (14:13 +0200)
'vshReadlineInit' is called when interactive virsh is started but also
on each call to 'cmdComplete'. Calling it repeatedly (using the
'complete' command interactively, or multiple times in batch mode) leaks
the buffers for history file configuration.

Avoid multiple setups of this function by returning success in case the
history file config is already present.

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

index 05de54b5b0fd7f0bf7ac9941bee29f79d510607c..f954f7af7702930cd834836ca99a41289ae40e0f 100644 (file)
@@ -2908,6 +2908,10 @@ vshReadlineInit(vshControl *ctl)
     const char *break_characters = " \t\n`@$><=;|&{(";
     const char *quote_characters = "\"'";
 
+    /* initialize readline stuff only once */
+    if (ctl->historydir)
+        return 0;
+
     /* Opaque data for autocomplete callbacks. */
     autoCompleteOpaque = ctl;