Problem: Leaking memory from autocmd windows.
Solution: Free window when auc_win is not NULL.
}
ga_clear(&augroups);
- for (int i = 0; i < AUCMD_WIN_COUNT; ++i)
- if (aucmd_win[i].auc_win_used)
- {
- aucmd_win[i].auc_win_used = FALSE;
- win_remove(aucmd_win[i].auc_win, NULL);
- }
+ // aucmd_win[] is freed in win_free_all()
}
#endif
for (auc_idx = 0; auc_idx < AUCMD_WIN_COUNT; ++auc_idx)
if (!aucmd_win[auc_idx].auc_win_used)
{
- auc_win = win_alloc_popup_win();
+ if (aucmd_win[auc_idx].auc_win == NULL)
+ aucmd_win[auc_idx].auc_win = win_alloc_popup_win();
+ auc_win = aucmd_win[auc_idx].auc_win;
if (auc_win != NULL)
- {
- aucmd_win[auc_idx].auc_win = auc_win;
aucmd_win[auc_idx].auc_win_used = TRUE;
- }
break;
}
// Remove the window and frame from the tree of frames.
(void)winframe_remove(curwin, &dummy, NULL);
win_remove(curwin, NULL);
+
+ // The window is marked as not used, but it is not freed, it can be
+ // used again.
aucmd_win[aco->use_aucmd_win_idx].auc_win_used = FALSE;
last_status(FALSE); // may need to remove last status line
FOR_ALL_TAB_WINDOWS(tp, wp)
abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID,
NULL, NULL);
+ // window-local variables in autocmd windows
for (int i = 0; i < AUCMD_WIN_COUNT; ++i)
- if (aucmd_win[i].auc_win_used)
+ if (aucmd_win[i].auc_win != NULL)
abort = abort || set_ref_in_item(
&aucmd_win[i].auc_win->w_winvar.di_tv, copyID, NULL, NULL);
#ifdef FEAT_PROP_POPUP
#define AUCMD_WIN_COUNT 5
typedef struct {
- win_T *auc_win; // window used in aucmd_prepbuf()
- int auc_win_used; // this auc_win is being used
+ win_T *auc_win; // Window used in aucmd_prepbuf(). When not NULL the
+ // window has been allocated.
+ int auc_win_used; // This auc_win is being used.
} aucmdwin_T;
EXTERN aucmdwin_T aucmd_win[AUCMD_WIN_COUNT];
// restore curwin/curbuf and a few other things
aucmd_restbuf(&aco);
- }
- if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe))
- wipe_buffer(newbuf_to_wipe.br_buf, FALSE);
+ if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe))
+ wipe_buffer(newbuf_to_wipe.br_buf, FALSE);
+ }
// Add back the "dummy" flag, otherwise buflist_findname_stat() won't
// skip it.
FOR_ALL_TAB_WINDOWS(tp, wp)
win_free_lsize(wp);
for (int i = 0; i < AUCMD_WIN_COUNT; ++i)
- if (aucmd_win[i].auc_win_used)
+ if (aucmd_win[i].auc_win != NULL)
win_free_lsize(aucmd_win[i].auc_win);
#ifdef FEAT_PROP_POPUP
// global popup windows
}
}
for (int i = 0; i < AUCMD_WIN_COUNT; ++i)
- if (aucmd_win[i].auc_win_used
+ if (aucmd_win[i].auc_win != NULL
&& aucmd_win[i].auc_win->w_lines == NULL
&& win_alloc_lines(aucmd_win[i].auc_win) == FAIL)
{
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 967,
/**/
966,
/**/
tabpage_close(TRUE);
for (int i = 0; i < AUCMD_WIN_COUNT; ++i)
- if (aucmd_win[i].auc_win_used)
+ if (aucmd_win[i].auc_win != NULL)
{
(void)win_free_mem(aucmd_win[i].auc_win, &dummy, NULL);
- aucmd_win[i].auc_win_used = FALSE;
+ aucmd_win[i].auc_win = NULL;
}
while (firstwin != NULL)