]> granicus.if.org Git - vim/commitdiff
patch 8.2.2505: Vim9: crash after defining function with invalid return type v8.2.2505
authorBram Moolenaar <Bram@vim.org>
Fri, 12 Feb 2021 21:10:21 +0000 (22:10 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 12 Feb 2021 21:10:21 +0000 (22:10 +0100)
Problem:    Vim9: crash after defining function with invalid return type.
Solution:   Clear function growarrays.  Fix memory leak.

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index cea25a4314e7b3c68d41f9b9b0a11a3ecfcea1fc..4bcd974e50847415e0462f7512ff6f483765efbd 100644 (file)
@@ -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()
index c9b15fd638a0c677d66e19a1b6b418456d182a04..3e1762189651f8bbf02ca75769896b3ae03335c4 100644 (file)
@@ -3955,8 +3955,15 @@ define_function(exarg_T *eap, char_u *name_arg)
 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);
index 465b5b04a230689f015dc9977e0da1ee413668a2..6ec23a95aa92c8ddd22c3ad1508607a930bd1773 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2505,
 /**/
     2504,
 /**/