]> granicus.if.org Git - vim/commitdiff
patch 8.2.3951: Vim9: memory leak when text after a nested function v8.2.3951
authorBram Moolenaar <Bram@vim.org>
Thu, 30 Dec 2021 17:09:05 +0000 (17:09 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 30 Dec 2021 17:09:05 +0000 (17:09 +0000)
Problem:    Vim9: memory leak when text after a nested function.
Solution:   Free the function if text is found after "enddef".

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

index 7a5f0f1a4012da267db4abd07a43d7f4c42672a1..7b2f5016c3fac979eae3b9e81c1312c9fa515155 100644 (file)
@@ -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>)
index 56d900dc2c06756657925cf2c5242cfd9b9cae64..649d2fc601416a9de51291d0b71d8859e13d8b87 100644 (file)
@@ -749,6 +749,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3951,
 /**/
     3950,
 /**/
index 8882bfe107b8d9471510134521e6f6e1b299221f..272368e76503a9f2a17955a2ee451968cd5840fd 100644 (file)
@@ -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;
     }