# HG changeset patch # User Bram Moolenaar # Date 1613164503 -3600 # Node ID e979bf909fd85dc50870d1f5e48d243a9e83cc75 # Parent 2f0d80c68af149ad104b3a645117f018193195eb patch 8.2.2505: Vim9: crash after defining function with invalid return type Commit: https://github.com/vim/vim/commit/31842cd0772b557eb9584a13740430db29de8a51 Author: Bram Moolenaar Date: Fri Feb 12 22:10:21 2021 +0100 patch 8.2.2505: Vim9: crash after defining function with invalid return type Problem: Vim9: crash after defining function with invalid return type. Solution: Clear function growarrays. Fix memory leak. diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -254,6 +254,21 @@ def Test_return_invalid() defcompile END CheckScriptFailure(lines, 'E1010:', 2) + + lines =<< trim END + vim9script + def Test(Fun: func(number): number): list + return map([1, 2, 3], (_, i) => Fun(i)) + enddef + defcompile + def Inc(nr: number): nr + return nr + 2 + enddef + echo Test(Inc) + END + # doing this twice was leaking memory + CheckScriptFailure(lines, 'E1010:') + CheckScriptFailure(lines, 'E1010:') enddef func Increment() diff --git a/src/userfunc.c b/src/userfunc.c --- a/src/userfunc.c +++ b/src/userfunc.c @@ -3955,8 +3955,15 @@ define_function(exarg_T *eap, char_u *na erret: ga_clear_strings(&newargs); ga_clear_strings(&default_args); + if (fp != NULL) + { + ga_init(&fp->uf_args); + ga_init(&fp->uf_def_args); + } errret_2: ga_clear_strings(&newlines); + if (fp != NULL) + VIM_CLEAR(fp->uf_arg_types); ret_free: ga_clear_strings(&argtypes); vim_free(skip_until); diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2505, +/**/ 2504, /**/ 2503,