From 5c3d1e3258872381831f419765f2969f45caaa11 Mon Sep 17 00:00:00 2001 From: Girish Palya Date: Tue, 22 Apr 2025 19:52:16 +0200 Subject: [PATCH] patch 9.1.1331: Leaking memory with cmdcomplete() Problem: Leaking memory with cmdcomplete() (zeertzjq, after v9.1.1329) Solution: free the memory (Girish Palya) closes: #17190 Signed-off-by: Girish Palya Signed-off-by: Christian Brabandt --- runtime/doc/builtin.txt | 4 ++-- src/cmdexpand.c | 3 +++ src/ex_getln.c | 3 +-- src/testdir/test_autocmd.vim | 6 ++++++ src/version.c | 2 ++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 70f3c88e3a..0a1c3b1272 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -1,4 +1,4 @@ -*builtin.txt* For Vim version 9.1. Last change: 2025 Apr 21 +*builtin.txt* For Vim version 9.1. Last change: 2025 Apr 23 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1834,7 +1834,7 @@ clearmatches([{win}]) *clearmatches()* Return type: |Number| -cmdcomplete_info([{what}]) *cmdcomplete_info()* +cmdcomplete_info() *cmdcomplete_info()* Returns a |Dictionary| with information about cmdline completion. See |cmdline-completion|. The items are: diff --git a/src/cmdexpand.c b/src/cmdexpand.c index 45f69bb2fe..5b87d7804a 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -1244,7 +1244,10 @@ showmatches(expand_T *xp, int wildmenu UNUSED) // Save cmdline before expansion if (ccline->cmdbuff != NULL) + { + vim_free(cmdline_orig); cmdline_orig = vim_strnsave(ccline->cmdbuff, ccline->cmdlen); + } if (xp->xp_numfiles == -1) { diff --git a/src/ex_getln.c b/src/ex_getln.c index 1137708aeb..8445236acc 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1916,8 +1916,7 @@ getcmdline_int( } // Trigger CmdlineLeavePre autocommand - if (ccline.cmdfirstc != NUL && (c == '\n' || c == '\r' || c == K_KENTER - || c == ESC || c == Ctrl_C)) + if (c == '\n' || c == '\r' || c == K_KENTER || c == ESC || c == Ctrl_C) trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVEPRE); // The wildmenu is cleared if the pressed key is not used for diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index ae587117e4..6f83b9caea 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -2038,6 +2038,12 @@ func Test_Cmdline_Trigger() call assert_equal('', g:log) call feedkeys(":echo hello", "tx") call assert_equal('CmdlineLeavePre', g:log) + let g:count = 0 + autocmd CmdlineLeavePre * let g:count += 1 + call feedkeys(":let c = input('? ')\B\", "tx") + call assert_equal(2, g:count) + unlet! g:count + unlet! g:log bw! endfunc diff --git a/src/version.c b/src/version.c index 048788e60f..2209282f81 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1331, /**/ 1330, /**/