mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 01:16:31 +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;
|
bool islambda = false;
|
||||||
char_u numbuf[NUMBUFLEN];
|
char_u numbuf[NUMBUFLEN];
|
||||||
char_u *name;
|
char_u *name;
|
||||||
|
typval_T *tv_to_free[MAX_FUNC_ARGS];
|
||||||
|
int tv_to_free_len = 0;
|
||||||
proftime_T wait_start;
|
proftime_T wait_start;
|
||||||
proftime_T call_start;
|
proftime_T call_start;
|
||||||
int started_profiling = false;
|
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 = isdefault ? def_rettv : argvars[i];
|
||||||
v->di_tv.v_lock = VAR_FIXED;
|
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) {
|
if (addlocal) {
|
||||||
// Named arguments can be accessed without the "a:" prefix in lambda
|
// Named arguments can be accessed without the "a:" prefix in lambda
|
||||||
// expressions. Add to the l: dict.
|
// 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;
|
did_emsg |= save_did_emsg;
|
||||||
depth--;
|
depth--;
|
||||||
|
for (int i = 0; i < tv_to_free_len; i++) {
|
||||||
|
tv_clear(tv_to_free[i]);
|
||||||
|
}
|
||||||
cleanup_function_call(fc);
|
cleanup_function_call(fc);
|
||||||
|
|
||||||
if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0) {
|
if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0) {
|
||||||
|
@@ -1071,10 +1071,10 @@ func Test_inputlist()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_balloon_show()
|
func Test_balloon_show()
|
||||||
if has('balloon_eval')
|
CheckFeature balloon_eval
|
||||||
|
|
||||||
" This won't do anything but must not crash either.
|
" This won't do anything but must not crash either.
|
||||||
call balloon_show('hi!')
|
call balloon_show('hi!')
|
||||||
endif
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_shellescape()
|
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) .. '>"'))
|
call assert_equal("\x80\xfc\b\xfd\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX\x80\xfeX", eval('"\<M-' .. nr2char(0x40000000) .. '>"'))
|
||||||
endfunc
|
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
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user