changeset 26845:a6ccb6ec581c v8.2.3951

patch 8.2.3951: Vim9: memory leak when text after a nested function Commit: https://github.com/vim/vim/commit/d293981d2b76b40013143fe2302b910585e50808 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 30 17:09:05 2021 +0000 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".
author Bram Moolenaar <Bram@vim.org>
date Thu, 30 Dec 2021 18:15:03 +0100
parents 90ab085d8d8f
children fbe7e8fa0d2f
files src/testdir/test_vim9_func.vim src/version.c src/vim9compile.c
diffstat 3 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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<string>)
--- a/src/version.c
+++ b/src/version.c
@@ -750,6 +750,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3951,
+/**/
     3950,
 /**/
     3949,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -889,6 +889,7 @@ compile_nested_function(exarg_T *eap, cc
 	semsg(_(e_text_found_after_str_str),
 	      eap->cmdidx == CMD_def ? "enddef" : "endfunction", eap->nextcmd);
 	r = FAIL;
+	func_ptr_unref(ufunc);
 	goto theend;
     }