From de72f9098a7287615dc8bbb6293732ac546f51ac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 Aug 2022 15:44:15 +0800 Subject: [PATCH] vim-patch:8.2.0061: the execute stack can grow big and never shrinks Problem: The execute stack can grow big and never shrinks. Solution: Reduce the size in gargage collect. https://github.com/vim/vim/commit/3fbcc128cbd2311819cc5a7bb89e45669860f008 --- src/nvim/eval.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f0b76b9a10..ff94cf5944 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4188,6 +4188,23 @@ bool garbage_collect(bool testing) garbage_collect_at_exit = false; } + // The execution stack can grow big, limit the size. + if (exestack.ga_maxlen - exestack.ga_len > 500) { + // Keep 150% of the current size, with a minimum of the growth size. + int n = exestack.ga_len / 2; + if (n < exestack.ga_growsize) { + n = exestack.ga_growsize; + } + + // Don't make it bigger though. + if (exestack.ga_len + n < exestack.ga_maxlen) { + size_t new_len = (size_t)exestack.ga_itemsize * (size_t)(exestack.ga_len + n); + char *pp = xrealloc(exestack.ga_data, new_len); + exestack.ga_maxlen = exestack.ga_len + n; + exestack.ga_data = pp; + } + } + // We advance by two (COPYID_INC) because we add one for items referenced // through previous_funccal. const int copyID = get_copyID();