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) {
|
||||
|
@@ -1071,10 +1071,10 @@ func Test_inputlist()
|
||||
endfunc
|
||||
|
||||
func Test_balloon_show()
|
||||
if has('balloon_eval')
|
||||
" This won't do anything but must not crash either.
|
||||
call balloon_show('hi!')
|
||||
endif
|
||||
CheckFeature balloon_eval
|
||||
|
||||
" This won't do anything but must not crash either.
|
||||
call balloon_show('hi!')
|
||||
endfunc
|
||||
|
||||
func Test_shellescape()
|
||||
@@ -1448,4 +1448,12 @@ func Test_nr2char()
|
||||
call assert_equal("\x80\xfc\b\xfd\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x40000000) .. '>"'))
|
||||
endfunc
|
||||
|
||||
func HasDefault(msg = 'msg')
|
||||
return a:msg
|
||||
endfunc
|
||||
|
||||
func Test_default_arg_value()
|
||||
call assert_equal('msg', HasDefault())
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
Reference in New Issue
Block a user