commit 2f371ad7d0294072d407bb05816425b5694d1935
parent 0b2b1b01850a18546508007edb87866714c85dde
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed, 17 Apr 2024 06:52:29 +0800
vim-patch:9.1.0341: Problem: a few memory leaks are found (#28382)
Problem: a few memory leaks are found
(LuMingYinDetect )
Solution: properly free the memory
Fixes the following problems:
- Memory leak in f_maplist()
fixes: vim/vim#14486
- Memory leak in option.c
fixes: vim/vim#14485
- Memory leak in f_resolve()
fixes: vim/vim#14484
- Memory leak in f_autocmd_get()
related: vim/vim#14474
- Memory leak in dict_extend_func()
fixes: vim/vim#14477
fixes: vim/vim#14238
closes: vim/vim#14517
https://github.com/vim/vim/commit/29269a71b5ac8a87c6c4beca35c173a19a2c9398
Co-authored-by: Christian Brabandt <cb@256bit.org>
Diffstat:
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
@@ -2019,6 +2019,9 @@ static void extend_dict(typval_T *argvars, const char *arg_errmsg, bool is_new,
action = tv_get_string_chk(&argvars[2]);
if (action == NULL) {
+ if (is_new) {
+ tv_dict_unref(d1);
+ }
return; // Type error; error message already given.
}
size_t i;
@@ -2028,6 +2031,9 @@ static void extend_dict(typval_T *argvars, const char *arg_errmsg, bool is_new,
}
}
if (i == 3) {
+ if (is_new) {
+ tv_dict_unref(d1);
+ }
semsg(_(e_invarg2), action);
return;
}
diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim
@@ -1441,4 +1441,10 @@ func Test_indexof()
delfunc TestIdx
endfunc
+func Test_extendnew_leak()
+ " This used to leak memory
+ for i in range(100) | silent! call extendnew([], [], []) | endfor
+ for i in range(100) | silent! call extendnew({}, {}, {}) | endfor
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab