mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 17:06:30 +00:00
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:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user