patch 8.2.1711: Vim9: leaking memory when using partial
Problem: Vim9: leaking memory when using partial.
Solution: Do delete the function even when it was compiled.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index a70ed5a..a6b4ba4 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2593,6 +2593,9 @@
// The return type will now be known.
set_function_type(ufunc);
+ // The function reference count will be 1. When the ISN_FUNCREF
+ // instruction is deleted the reference count is decremented and the
+ // function is freed.
return generate_FUNCREF(cctx, ufunc);
}
@@ -7424,6 +7427,18 @@
}
}
+/*
+ * Used when a user function is about to be deleted: remove the pointer to it.
+ * The entry in def_functions is then unused.
+ */
+ void
+unlink_def_function(ufunc_T *ufunc)
+{
+ dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + ufunc->uf_dfunc_idx;
+
+ dfunc->df_ufunc = NULL;
+}
+
#if defined(EXITFREE) || defined(PROTO)
/*
* Free all functions defined with ":def".