From 66369cd9d03bf4b09c354f4a23ed24adad834408 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 29 Apr 2020 00:31:01 -0400 Subject: vim-patch:8.1.0800: may use a lot of memory when a function refers itself Problem: May use a lot of memory when a function creates a cyclic reference. Solution: After saving a funccal many times, invoke the garbage collector. (closes vim/vim#3835) https://github.com/vim/vim/commit/4456ab527a6a5faae9287f3bd2e52cc18966cfb0 --- src/nvim/eval/userfunc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index c55a29c67c..6e3c6c592a 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -592,6 +592,8 @@ static void cleanup_function_call(funccall_T *fc) if (!fc_referenced(fc)) { free_funccal(fc, false); } else { + static int made_copy = 0; + // "fc" is still in use. This can happen when returning "a:000", // assigning "l:" to a global variable or defining a closure. // Link "fc" in the list for garbage collection later. @@ -607,6 +609,15 @@ static void cleanup_function_call(funccall_T *fc) TV_LIST_ITER(&fc->l_varlist, li, { tv_copy(TV_LIST_ITEM_TV(li), TV_LIST_ITEM_TV(li)); }); + + if (++made_copy == 10000) { + // We have made a lot of copies. This can happen when + // repetitively calling a function that creates a reference to + // itself somehow. Call the garbage collector here to avoid using + // too much memory. + made_copy = 0; + (void)garbage_collect(false); + } } } -- cgit From a89d64b68760094f9da3b8b10442c1f86942351c Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 29 Apr 2020 00:35:44 -0400 Subject: vim-patch:8.1.0868: crash if triggering garbage collector after a function call Problem: Crash if triggering garbage collector after a function call. (Michael Henry) Solution: Don't call the garbage collector right away, do it later. (closes vim/vim#3894) https://github.com/vim/vim/commit/889da2f2438c8168f9a25dc776360b81109bad44 --- src/nvim/eval/userfunc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 6e3c6c592a..ae8557a8bc 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -613,10 +613,10 @@ static void cleanup_function_call(funccall_T *fc) if (++made_copy == 10000) { // We have made a lot of copies. This can happen when // repetitively calling a function that creates a reference to - // itself somehow. Call the garbage collector here to avoid using + // itself somehow. Call the garbage collector soon to avoid using // too much memory. made_copy = 0; - (void)garbage_collect(false); + want_garbage_collect = true; } } } -- cgit