changeset 23925:e979bf909fd8 v8.2.2505

patch 8.2.2505: Vim9: crash after defining function with invalid return type Commit: https://github.com/vim/vim/commit/31842cd0772b557eb9584a13740430db29de8a51 Author: Bram Moolenaar <Bram@vim.org> 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.
author Bram Moolenaar <Bram@vim.org>
date Fri, 12 Feb 2021 22:15:03 +0100
parents 2f0d80c68af1
children 1a41fde53816
files src/testdir/test_vim9_func.vim src/userfunc.c src/version.c
diffstat 3 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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<number>
+          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()
--- 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);
--- 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,