0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2020-05-03 15:38:16 +02:00
parent 5adc55cb74
commit f7779c63d4
7 changed files with 83 additions and 71 deletions

View File

@@ -3703,6 +3703,24 @@ partial_free(partial_T *pt)
}
else
func_ptr_unref(pt->pt_func);
if (pt->pt_funcstack != NULL)
{
// Decrease the reference count for the context of a closure. If down
// to zero free it and clear the variables on the stack.
if (--pt->pt_funcstack->fs_refcount == 0)
{
garray_T *gap = &pt->pt_funcstack->fs_ga;
typval_T *stack = gap->ga_data;
for (i = 0; i < gap->ga_len; ++i)
clear_tv(stack + i);
ga_clear(gap);
vim_free(pt->pt_funcstack);
}
pt->pt_funcstack = NULL;
}
vim_free(pt);
}
@@ -4336,6 +4354,15 @@ set_ref_in_item(
for (i = 0; i < pt->pt_argc; ++i)
abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID,
ht_stack, list_stack);
if (pt->pt_funcstack != NULL)
{
typval_T *stack = pt->pt_funcstack->fs_ga.ga_data;
for (i = 0; i < pt->pt_funcstack->fs_ga.ga_len; ++i)
abort = abort || set_ref_in_item(stack + i, copyID,
ht_stack, list_stack);
}
}
}
#ifdef FEAT_JOB_CHANNEL