summaryrefslogtreecommitdiff
path: root/src/userfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-05-03 15:38:16 +0200
committerBram Moolenaar <Bram@vim.org>2020-05-03 15:38:16 +0200
commitf7779c63d4fe531e2483502d4441f24802342768 (patch)
tree1d630be90ef6aa51ec11ce5eac248dcd92acb041 /src/userfunc.c
parent5adc55cb746893c6ddf7865ff654582902dee2e3 (diff)
downloadvim-git-f7779c63d4fe531e2483502d4441f24802342768.tar.gz
patch 8.2.0684: Vim9: memory leak when using lambdav8.2.0684
Problem: Vim9: memory leak when using lambda. Solution: Move the funccal context to the partial. Free the function when exiting.
Diffstat (limited to 'src/userfunc.c')
-rw-r--r--src/userfunc.c13
1 files changed, 5 insertions, 8 deletions
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);