diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-04-15 18:15:45 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2021-04-15 18:30:04 -0400 |
commit | 97288e73c27d45b0fadbd6efa437fe54bc58b5e3 (patch) | |
tree | 1c28ab9cb3df836e149a92ca878548b1b4758f1e /src/nvim/eval/userfunc.c | |
parent | 7d3f31c0643f40645292e03565d18961e8cd72d7 (diff) | |
download | rneovim-97288e73c27d45b0fadbd6efa437fe54bc58b5e3.tar.gz rneovim-97288e73c27d45b0fadbd6efa437fe54bc58b5e3.tar.bz2 rneovim-97288e73c27d45b0fadbd6efa437fe54bc58b5e3.zip |
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.
https://github.com/vim/vim/commit/b47bed2f7ada4dfae78f76f27473b83507e40315
Diffstat (limited to 'src/nvim/eval/userfunc.c')
-rw-r--r-- | src/nvim/eval/userfunc.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 689d05e079..00260bc3f7 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -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) { |