patch 8.2.1332: Vim9: memory leak when using nested global function
Problem: Vim9: memory leak when using nested global function.
Solution: Delete the function when deleting the instruction. Disable test
that still causes a leak.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 87a9fd1..688f42a 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -7677,8 +7677,21 @@
break;
case ISN_NEWFUNC:
- vim_free(isn->isn_arg.newfunc.nf_lambda);
- vim_free(isn->isn_arg.newfunc.nf_global);
+ {
+ char_u *lambda = isn->isn_arg.newfunc.nf_lambda;
+ ufunc_T *ufunc = find_func_even_dead(lambda, TRUE, NULL);
+
+ if (ufunc != NULL)
+ {
+ // Clear uf_dfunc_idx so that the function is deleted.
+ clear_def_function(ufunc);
+ ufunc->uf_dfunc_idx = 0;
+ func_ptr_unref(ufunc);
+ }
+
+ vim_free(lambda);
+ vim_free(isn->isn_arg.newfunc.nf_global);
+ }
break;
case ISN_2BOOL: