changeset 30871:86683574317a v9.0.0770

patch 9.0.0770: quickfix commands may keep memory allocated Commit: https://github.com/vim/vim/commit/d8cd6f7427bc89aa38f42cc44f58bf5fb5f0f972 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Oct 16 11:30:48 2022 +0100 patch 9.0.0770: quickfix commands may keep memory allocated Problem: Quickfix commands may keep memory allocated. Solution: Free memory when it's a bit much. (Yegappan Lakshmanan, closes #11379)
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Oct 2022 12:45:05 +0200
parents dc895309ea0c
children e96a9b7caa0d
files src/quickfix.c src/version.c
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -236,13 +236,29 @@ qfga_get(void)
 	ga_init2(&qfga, 1, 256);
     }
 
-    // Retain ga_data from previous use.  Reset the length to zero.
+    // Reset the length to zero.  Retain ga_data from previous use to avoid
+    // many alloc/free calls.
     qfga.ga_len = 0;
 
     return &qfga;
 }
 
 /*
+ * The "qfga" grow array buffer is reused across multiple quickfix commands as
+ * a temporary buffer to reduce the number of alloc/free calls.  But if the
+ * buffer size is large, then to avoid holding on to that memory, clear the
+ * grow array.  Otherwise just reset the grow array length.
+ */
+    static void
+qfga_clear(void)
+{
+    if (qfga.ga_maxlen > 1000)
+	ga_clear(&qfga);
+    else
+	qfga.ga_len = 0;
+}
+
+/*
  * Maximum number of bytes allowed per line while reading a errorfile.
  */
 #define LINE_MAXLEN 4096
@@ -3335,6 +3351,8 @@ qf_jump_print_msg(
 	msg_scroll = FALSE;
     msg_attr_keep((char *)gap->ga_data, 0, TRUE);
     msg_scroll = i;
+
+    qfga_clear();
 }
 
 /*
@@ -3744,6 +3762,7 @@ qf_list(exarg_T *eap)
 
 	ui_breakcheck();
     }
+    qfga_clear();
 }
 
 /*
@@ -4820,6 +4839,8 @@ qf_fill_buffer(qf_list_T *qfl, buf_T *bu
 	if (old_last == NULL)
 	    // Delete the empty line which is now at the end
 	    (void)ml_delete(lnum + 1);
+
+	qfga_clear();
     }
 
     // correct cursor position
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    770,
+/**/
     769,
 /**/
     768,