Mercurial > vim
diff src/userfunc.c @ 20257:683c2da4982b v8.2.0684
patch 8.2.0684: Vim9: memory leak when using lambda
Commit: https://github.com/vim/vim/commit/f7779c63d4fe531e2483502d4441f24802342768
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 3 15:38:16 2020 +0200
patch 8.2.0684: Vim9: memory leak when using lambda
Problem: Vim9: memory leak when using lambda.
Solution: Move the funccal context to the partial. Free the function when
exiting.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 03 May 2020 15:45:05 +0200 |
parents | aac52c32a91f |
children | 49b50843e725 |
line wrap: on
line diff
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -1016,16 +1016,17 @@ func_clear(ufunc_T *fp, int force) /* * Free a function and remove it from the list of functions. Does not free * what a function contains, call func_clear() first. + * When "force" is TRUE we are exiting. */ static void -func_free(ufunc_T *fp) +func_free(ufunc_T *fp, int force) { // Only remove it when not done already, otherwise we would remove a newer // version of the function with the same name. if ((fp->uf_flags & (FC_DELETED | FC_REMOVED)) == 0) func_remove(fp); - if ((fp->uf_flags & FC_DEAD) == 0) + if ((fp->uf_flags & FC_DEAD) == 0 || force) vim_free(fp); } @@ -1037,7 +1038,7 @@ func_free(ufunc_T *fp) func_clear_free(ufunc_T *fp, int force) { func_clear(fp, force); - func_free(fp); + func_free(fp, force); } @@ -1664,7 +1665,7 @@ free_all_functions(void) ++skipped; else { - func_free(fp); + func_free(fp, FALSE); skipped = 0; break; } @@ -4392,8 +4393,6 @@ set_ref_in_functions(int copyID) fp = HI2UF(hi); if (!func_name_refcount(fp->uf_name)) abort = abort || set_ref_in_func(NULL, fp, copyID); - else if (fp->uf_dfunc_idx >= 0) - abort = abort || set_ref_in_dfunc(fp, copyID); } } return abort; @@ -4441,8 +4440,6 @@ set_ref_in_func(char_u *name, ufunc_T *f { for (fc = fp->uf_scoped; fc != NULL; fc = fc->func->uf_scoped) abort = abort || set_ref_in_funccal(fc, copyID); - if (fp->uf_dfunc_idx >= 0) - abort = abort || set_ref_in_dfunc(fp, copyID); } vim_free(tofree);