diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index a54056164e..9d6f7d972c 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -5321,6 +5321,7 @@ static void reduce_string(typval_T *argvars, typval_T *expr, typval_T *rettv) for (; *p != NUL; p += len) { typval_T argv[3]; argv[0] = *rettv; + rettv->v_type = VAR_UNKNOWN; len = utfc_ptr2len(p); argv[1] = (typval_T){ .v_type = VAR_STRING, diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim index 78d3a19cfb..f40a4290cc 100644 --- a/test/old/testdir/test_listdict.vim +++ b/test/old/testdir/test_listdict.vim @@ -1066,6 +1066,14 @@ func Test_reduce() " call assert_fails('echo reduce([1], test_null_function())', 'E1132:') " Nvim doesn't have null partials " call assert_fails('echo reduce([1], test_null_partial())', 'E1132:') + + " did cause double free + function! OuterReduce() + vim9 echo reduce('ab', 42) + endfunction + "call assert_fails('call OuterReduce()', 'E1024:') + call assert_fails("echo reduce('ab', 'NoSuchFunc')", 'E117:') + delfunc OuterReduce endfunc " splitting a string to a List using split()