From f7779c63d4fe531e2483502d4441f24802342768 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 3 May 2020 15:38:16 +0200 Subject: 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. --- src/userfunc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/userfunc.c') diff --git a/src/userfunc.c b/src/userfunc.c index 6aee37795..4dac28126 100644 --- 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 *fp_in, int copyID) { 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); -- cgit v1.2.1