From: Bram Moolenaar Date: Thu, 30 Dec 2021 17:09:05 +0000 (+0000) Subject: patch 8.2.3951: Vim9: memory leak when text after a nested function X-Git-Tag: v8.2.3951 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d293981d2b76b40013143fe2302b910585e50808;p=vim patch 8.2.3951: Vim9: memory leak when text after a nested function Problem: Vim9: memory leak when text after a nested function. Solution: Free the function if text is found after "enddef". --- diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index 7a5f0f1a4..7b2f5016c 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -1493,9 +1493,20 @@ def Test_call_varargs_only() enddef def Test_using_var_as_arg() - writefile(['def Func(x: number)', 'var x = 234', 'enddef', 'defcompile'], 'Xdef') - assert_fails('so Xdef', 'E1006:', '', 1, 'Func') - delete('Xdef') + var lines =<< trim END + def Func(x: number) + var x = 234 + enddef + END + CheckDefFailure(lines, 'E1006:') + + lines =<< trim END + def Func(Ref: number) + def Ref() + enddef + enddef + END + CheckDefFailure(lines, 'E1073:') enddef def DictArg(arg: dict) diff --git a/src/version.c b/src/version.c index 56d900dc2..649d2fc60 100644 --- a/src/version.c +++ b/src/version.c @@ -749,6 +749,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 3951, /**/ 3950, /**/ diff --git a/src/vim9compile.c b/src/vim9compile.c index 8882bfe10..272368e76 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -889,6 +889,7 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, char_u **line_to_free) semsg(_(e_text_found_after_str_str), eap->cmdidx == CMD_def ? "enddef" : "endfunction", eap->nextcmd); r = FAIL; + func_ptr_unref(ufunc); goto theend; }