Skip to content

Commit 79efa2e

Browse files
committed
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Problem: Vim9: leaking memory when inline function has an error. Solution: Free the partially allocated function.
1 parent 7007e31 commit 79efa2e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/userfunc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static char *e_funcref = N_("E718: Funcref required");
3535
static char *e_nofunc = N_("E130: Unknown function: %s");
3636

3737
static 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
4042
func_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

10501050
erret:
@@ -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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2663,
753755
/**/
754756
2662,
755757
/**/

0 commit comments

Comments
 (0)