diff src/vim9execute.c @ 22314:41e118669df3 v8.2.1706

patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error Commit: https://github.com/vim/vim/commit/7cbfaa51de7b225effdc79a008c71a5551883c38 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 18 21:25:32 2020 +0200 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error Problem: Vim9: crash after running into the "Multiple closures" error. Solution: When a function fails still update any closures. (closes https://github.com/vim/vim/issues/6973)
author Bram Moolenaar <Bram@vim.org>
date Fri, 18 Sep 2020 21:30:04 +0200
parents 74d0a7a30583
children 663cba20a5a5
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2676,15 +2676,11 @@ call_def_function(
 	continue;
 
 func_return:
-	// Restore previous function. If the frame pointer is zero then there
-	// is none and we are done.
+	// Restore previous function. If the frame pointer is where we started
+	// then there is none and we are done.
 	if (ectx.ec_frame_idx == initial_frame_idx)
-	{
-	    if (handle_closure_in_use(&ectx, FALSE) == FAIL)
-		// only fails when out of memory
-		goto failed;
 	    goto done;
-	}
+
 	if (func_return(&ectx) == FAIL)
 	    // only fails when out of memory
 	    goto failed;
@@ -2703,6 +2699,10 @@ done:
     ret = OK;
 
 failed:
+    // Also deal with closures when failed, they may already be in use
+    // somewhere.
+    handle_closure_in_use(&ectx, FALSE);
+
     // When failed need to unwind the call stack.
     while (ectx.ec_frame_idx != initial_frame_idx)
 	func_return(&ectx);