vim-patch:8.2.2764: memory leak when default function argument is allocated

Problem:    Memory leak when default function argument is allocated.
Solution:   Free the expression result.
b47bed2f7a
This commit is contained in:
Jan Edmund Lazo
2021-04-15 18:15:45 -04:00
parent 7d3f31c064
commit 97288e73c2
2 changed files with 22 additions and 5 deletions

View File

@@ -833,6 +833,8 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
bool islambda = false;
char_u numbuf[NUMBUFLEN];
char_u *name;
typval_T *tv_to_free[MAX_FUNC_ARGS];
int tv_to_free_len = 0;
proftime_T wait_start;
proftime_T call_start;
int started_profiling = false;
@@ -985,6 +987,11 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
v->di_tv = isdefault ? def_rettv : argvars[i];
v->di_tv.v_lock = VAR_FIXED;
if (isdefault) {
// Need to free this later, no matter where it's stored.
tv_to_free[tv_to_free_len++] = &v->di_tv;
}
if (addlocal) {
// Named arguments can be accessed without the "a:" prefix in lambda
// expressions. Add to the l: dict.
@@ -1209,7 +1216,9 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
did_emsg |= save_did_emsg;
depth--;
for (int i = 0; i < tv_to_free_len; i++) {
tv_clear(tv_to_free[i]);
}
cleanup_function_call(fc);
if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0) {