1
0
forked from aniani/vim

patch 8.2.3771: Vim9: accessing freed memory when checking type

Problem:    Vim9: accessing freed memory when checking type.
Solution:   Make a copy of a function type.
This commit is contained in:
Bram Moolenaar
2021-12-10 10:37:38 +00:00
parent dee78e1ce8
commit dd297bc11d
5 changed files with 49 additions and 3 deletions

View File

@@ -1224,6 +1224,25 @@ def Test_set_opfunc_to_lambda()
CheckScriptSuccess(lines)
enddef
def Test_lambda_type_allocated()
# Check that unreferencing a partial using a lambda can use the variable type
# after the lambda has been freed and does not leak memory.
var lines =<< trim END
vim9script
func MyomniFunc1(val, findstart, base)
return a:findstart ? 0 : []
endfunc
var Lambda = (a, b) => MyomniFunc1(19, a, b)
&omnifunc = Lambda
Lambda = (a, b) => MyomniFunc1(20, a, b)
&omnifunc = string(Lambda)
Lambda = (a, b) => strlen(a)
END
CheckScriptSuccess(lines)
enddef
" Default arg and varargs
def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
var res = one .. ',' .. two