@@ -1049,6 +1049,21 @@ cleanup_function_call(funccall_T *fc)
10491049 }
10501050 }
10511051}
1052+
1053+ /*
1054+ * There are two kinds of function names:
1055+ * 1. ordinary names, function defined with :function or :def
1056+ * 2. numbered functions and lambdas
1057+ * For the first we only count the name stored in func_hashtab as a reference,
1058+ * using function() does not count as a reference, because the function is
1059+ * looked up by name.
1060+ */
1061+ static int
1062+ func_name_refcount (char_u * name )
1063+ {
1064+ return isdigit (* name ) || * name == '<' ;
1065+ }
1066+
10521067/*
10531068 * Unreference "fc": decrement the reference count and free it when it
10541069 * becomes zero. "fp" is detached from "fc".
@@ -1172,6 +1187,8 @@ func_free(ufunc_T *fp, int force)
11721187
11731188 if ((fp -> uf_flags & FC_DEAD ) == 0 || force )
11741189 {
1190+ if (fp -> uf_dfunc_idx > 0 )
1191+ unlink_def_function (fp );
11751192 VIM_CLEAR (fp -> uf_name_exp );
11761193 vim_free (fp );
11771194 }
@@ -1185,7 +1202,8 @@ func_free(ufunc_T *fp, int force)
11851202func_clear_free (ufunc_T * fp , int force )
11861203{
11871204 func_clear (fp , force );
1188- if (force || fp -> uf_dfunc_idx == 0 || (fp -> uf_flags & FC_COPY ))
1205+ if (force || fp -> uf_dfunc_idx == 0 || func_name_refcount (fp -> uf_name )
1206+ || (fp -> uf_flags & FC_COPY ))
11891207 func_free (fp , force );
11901208 else
11911209 fp -> uf_flags |= FC_DEAD ;
@@ -1730,20 +1748,6 @@ call_user_func_check(
17301748 return error ;
17311749}
17321750
1733- /*
1734- * There are two kinds of function names:
1735- * 1. ordinary names, function defined with :function
1736- * 2. numbered functions and lambdas
1737- * For the first we only count the name stored in func_hashtab as a reference,
1738- * using function() does not count as a reference, because the function is
1739- * looked up by name.
1740- */
1741- static int
1742- func_name_refcount (char_u * name )
1743- {
1744- return isdigit (* name ) || * name == '<' ;
1745- }
1746-
17471751static funccal_entry_T * funccal_stack = NULL ;
17481752
17491753/*
0 commit comments