diff src/eval.c @ 19001:1ebfb46710cd v8.2.0061

patch 8.2.0061: the execute stack can grow big and never shrinks Commit: https://github.com/vim/vim/commit/3fbcc128cbd2311819cc5a7bb89e45669860f008 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 30 19:19:53 2019 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Mon, 30 Dec 2019 19:30:03 +0100
parents 24941a950cc7
children d9ea4f0bfd34
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -3857,6 +3857,30 @@ garbage_collect(int testing)
 	garbage_collect_at_exit = FALSE;
     }
 
+    // The execution stack can grow big, limit the size.
+    if (exestack.ga_maxlen - exestack.ga_len > 500)
+    {
+	size_t	new_len;
+	char_u	*pp;
+	int	n;
+
+	// Keep 150% of the current size, with a minimum of the growth size.
+	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)
+	{
+	    new_len = exestack.ga_itemsize * (exestack.ga_len + n);
+	    pp = vim_realloc(exestack.ga_data, new_len);
+	    if (pp == NULL)
+		return FAIL;
+	    exestack.ga_maxlen = exestack.ga_len + n;
+	    exestack.ga_data = pp;
+	}
+    }
+
     // We advance by two because we add one for items referenced through
     // previous_funccal.
     copyID = get_copyID();