patch 8.2.3788: lambda for option that is a function may be freed
Problem: Lambda for option that is a function may be garbage collected.
Solution: Set a reference in the funcref. (Yegappan Lakshmanan,
closes #9330)
diff --git a/src/eval.c b/src/eval.c
index e2aa41b..64381f0 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -4516,6 +4516,18 @@
// callbacks in buffers
abort = abort || set_ref_in_buffers(copyID);
+ // 'completefunc', 'omnifunc' and 'thesaurusfunc' callbacks
+ abort = abort || set_ref_in_insexpand_funcs(copyID);
+
+ // 'operatorfunc' callback
+ abort = abort || set_ref_in_opfunc(copyID);
+
+ // 'tagfunc' callback
+ abort = abort || set_ref_in_tagfunc(copyID);
+
+ // 'imactivatefunc' and 'imstatusfunc' callbacks
+ abort = abort || set_ref_in_im_funcs(copyID);
+
#ifdef FEAT_LUA
abort = abort || set_ref_in_lua(copyID);
#endif
@@ -4744,6 +4756,22 @@
}
/*
+ * Mark the partial in callback 'cb' with "copyID".
+ */
+ int
+set_ref_in_callback(callback_T *cb, int copyID)
+{
+ typval_T tv;
+
+ if (cb->cb_name == NULL || *cb->cb_name == NUL || cb->cb_partial == NULL)
+ return FALSE;
+
+ tv.v_type = VAR_PARTIAL;
+ tv.vval.v_partial = cb->cb_partial;
+ return set_ref_in_item(&tv, copyID, NULL, NULL);
+}
+
+/*
* Mark all lists and dicts referenced through typval "tv" with "copyID".
* "list_stack" is used to add lists to be marked. Can be NULL.
* "ht_stack" is used to add hashtabs to be marked. Can be NULL.