@@ -35,6 +35,8 @@ static char *e_funcref = N_("E718: Funcref required");
3535static char * e_nofunc = N_ ("E130: Unknown function: %s" );
3636
3737static void funccal_unref (funccall_T * fc , ufunc_T * fp , int force );
38+ static void func_clear (ufunc_T * fp , int force );
39+ static int func_free (ufunc_T * fp , int force );
3840
3941 void
4042func_init ()
@@ -946,7 +948,7 @@ lambda_function_body(
946948{
947949 int evaluate = evalarg != NULL
948950 && (evalarg -> eval_flags & EVAL_EVALUATE );
949- ufunc_T * ufunc ;
951+ ufunc_T * ufunc = NULL ;
950952 exarg_T eap ;
951953 garray_T newlines ;
952954 char_u * cmdline = NULL ;
@@ -1000,10 +1002,7 @@ lambda_function_body(
10001002 goto erret ;
10011003 set_ufunc_name (ufunc , name );
10021004 if (hash_add (& func_hashtab , UF2HIKEY (ufunc )) == FAIL )
1003- {
1004- vim_free (ufunc );
10051005 goto erret ;
1006- }
10071006 ufunc -> uf_refcount = 1 ;
10081007 ufunc -> uf_args = * newargs ;
10091008 newargs -> ga_data = NULL ;
@@ -1045,6 +1044,7 @@ lambda_function_body(
10451044
10461045 rettv -> vval .v_partial = pt ;
10471046 rettv -> v_type = VAR_PARTIAL ;
1047+ ufunc = NULL ;
10481048 ret = OK ;
10491049
10501050erret :
@@ -1054,6 +1054,11 @@ lambda_function_body(
10541054 ga_clear_strings (& newlines );
10551055 ga_clear_strings (newargs );
10561056 ga_clear_strings (default_args );
1057+ if (ufunc != NULL )
1058+ {
1059+ func_clear (ufunc , TRUE);
1060+ func_free (ufunc , TRUE);
1061+ }
10571062 return ret ;
10581063}
10591064
0 commit comments