Mercurial > vim
comparison src/quickfix.c @ 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 | d7066cbac096 |
children | f55ddd3748f5 |
comparison
equal
deleted
inserted
replaced
30870:dc895309ea0c | 30871:86683574317a |
---|---|
234 { | 234 { |
235 initialized = TRUE; | 235 initialized = TRUE; |
236 ga_init2(&qfga, 1, 256); | 236 ga_init2(&qfga, 1, 256); |
237 } | 237 } |
238 | 238 |
239 // Retain ga_data from previous use. Reset the length to zero. | 239 // Reset the length to zero. Retain ga_data from previous use to avoid |
240 // many alloc/free calls. | |
240 qfga.ga_len = 0; | 241 qfga.ga_len = 0; |
241 | 242 |
242 return &qfga; | 243 return &qfga; |
244 } | |
245 | |
246 /* | |
247 * The "qfga" grow array buffer is reused across multiple quickfix commands as | |
248 * a temporary buffer to reduce the number of alloc/free calls. But if the | |
249 * buffer size is large, then to avoid holding on to that memory, clear the | |
250 * grow array. Otherwise just reset the grow array length. | |
251 */ | |
252 static void | |
253 qfga_clear(void) | |
254 { | |
255 if (qfga.ga_maxlen > 1000) | |
256 ga_clear(&qfga); | |
257 else | |
258 qfga.ga_len = 0; | |
243 } | 259 } |
244 | 260 |
245 /* | 261 /* |
246 * Maximum number of bytes allowed per line while reading a errorfile. | 262 * Maximum number of bytes allowed per line while reading a errorfile. |
247 */ | 263 */ |
3333 msg_scroll = TRUE; | 3349 msg_scroll = TRUE; |
3334 else if (!msg_scrolled && shortmess(SHM_OVERALL)) | 3350 else if (!msg_scrolled && shortmess(SHM_OVERALL)) |
3335 msg_scroll = FALSE; | 3351 msg_scroll = FALSE; |
3336 msg_attr_keep((char *)gap->ga_data, 0, TRUE); | 3352 msg_attr_keep((char *)gap->ga_data, 0, TRUE); |
3337 msg_scroll = i; | 3353 msg_scroll = i; |
3354 | |
3355 qfga_clear(); | |
3338 } | 3356 } |
3339 | 3357 |
3340 /* | 3358 /* |
3341 * Find a usable window for opening a file from the quickfix/location list. If | 3359 * Find a usable window for opening a file from the quickfix/location list. If |
3342 * a window is not found then open a new window. If 'newwin' is TRUE, then open | 3360 * a window is not found then open a new window. If 'newwin' is TRUE, then open |
3742 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2) | 3760 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2) |
3743 qf_list_entry(qfp, i, i == qfl->qf_index); | 3761 qf_list_entry(qfp, i, i == qfl->qf_index); |
3744 | 3762 |
3745 ui_breakcheck(); | 3763 ui_breakcheck(); |
3746 } | 3764 } |
3765 qfga_clear(); | |
3747 } | 3766 } |
3748 | 3767 |
3749 /* | 3768 /* |
3750 * Remove newlines and leading whitespace from an error message. | 3769 * Remove newlines and leading whitespace from an error message. |
3751 * Add the result to the grow array "gap". | 3770 * Add the result to the grow array "gap". |
4818 } | 4837 } |
4819 | 4838 |
4820 if (old_last == NULL) | 4839 if (old_last == NULL) |
4821 // Delete the empty line which is now at the end | 4840 // Delete the empty line which is now at the end |
4822 (void)ml_delete(lnum + 1); | 4841 (void)ml_delete(lnum + 1); |
4842 | |
4843 qfga_clear(); | |
4823 } | 4844 } |
4824 | 4845 |
4825 // correct cursor position | 4846 // correct cursor position |
4826 check_lnums(TRUE); | 4847 check_lnums(TRUE); |
4827 | 4848 |