0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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.
This commit is contained in:
Bram Moolenaar
2021-03-27 15:40:11 +01:00
parent 7007e31bde
commit 79efa2e3b3
2 changed files with 11 additions and 4 deletions

View File

@@ -35,6 +35,8 @@ static char *e_funcref = N_("E718: Funcref required");
static char *e_nofunc = N_("E130: Unknown function: %s"); static char *e_nofunc = N_("E130: Unknown function: %s");
static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force); static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force);
static void func_clear(ufunc_T *fp, int force);
static int func_free(ufunc_T *fp, int force);
void void
func_init() func_init()
@@ -946,7 +948,7 @@ lambda_function_body(
{ {
int evaluate = evalarg != NULL int evaluate = evalarg != NULL
&& (evalarg->eval_flags & EVAL_EVALUATE); && (evalarg->eval_flags & EVAL_EVALUATE);
ufunc_T *ufunc; ufunc_T *ufunc = NULL;
exarg_T eap; exarg_T eap;
garray_T newlines; garray_T newlines;
char_u *cmdline = NULL; char_u *cmdline = NULL;
@@ -1000,10 +1002,7 @@ lambda_function_body(
goto erret; goto erret;
set_ufunc_name(ufunc, name); set_ufunc_name(ufunc, name);
if (hash_add(&func_hashtab, UF2HIKEY(ufunc)) == FAIL) if (hash_add(&func_hashtab, UF2HIKEY(ufunc)) == FAIL)
{
vim_free(ufunc);
goto erret; goto erret;
}
ufunc->uf_refcount = 1; ufunc->uf_refcount = 1;
ufunc->uf_args = *newargs; ufunc->uf_args = *newargs;
newargs->ga_data = NULL; newargs->ga_data = NULL;
@@ -1045,6 +1044,7 @@ lambda_function_body(
rettv->vval.v_partial = pt; rettv->vval.v_partial = pt;
rettv->v_type = VAR_PARTIAL; rettv->v_type = VAR_PARTIAL;
ufunc = NULL;
ret = OK; ret = OK;
erret: erret:
@@ -1054,6 +1054,11 @@ erret:
ga_clear_strings(&newlines); ga_clear_strings(&newlines);
ga_clear_strings(newargs); ga_clear_strings(newargs);
ga_clear_strings(default_args); ga_clear_strings(default_args);
if (ufunc != NULL)
{
func_clear(ufunc, TRUE);
func_free(ufunc, TRUE);
}
return ret; return ret;
} }

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2663,
/**/ /**/
2662, 2662,
/**/ /**/