Problem: Possible crash when an BufLeave autocommand deletes the buffer.
Solution: Check for the window pointer being valid. Postpone freeing the
window until autocommands are done. (Yasuhiro Matsumoto)
unload_buf = TRUE;
#endif
- if (win != NULL)
+ if (win != NULL
+#ifdef FEAT_WINDOWS
+ && win_valid(win) /* in case autocommands closed the window */
+#endif
+ )
{
/* Set b_last_cursor when closing the last window for the buffer.
* Remember the last cursor position and window options of the buffer.
/*
* When stopping to execute autocommands, restore the search patterns and
- * the redo buffer. Free buffers in the au_pending_free_buf list.
+ * the redo buffer. Free any buffers in the au_pending_free_buf list and
+ * free any windows in the au_pending_free_win list.
*/
if (!autocmd_busy)
{
vim_free(au_pending_free_buf);
au_pending_free_buf = b;
}
+ while (au_pending_free_win != NULL)
+ {
+ win_T *w = au_pending_free_win->w_next;
+ vim_free(au_pending_free_win);
+ au_pending_free_win = w;
+ }
}
/*
* which one is preferred, au_new_curbuf is set to it */
EXTERN buf_T *au_new_curbuf INIT(= NULL);
-/* When deleting the buffer and autocmd_busy is TRUE, do not free the buffer
- * but link it in the list starting with au_pending_free_buf, using b_next.
- * Free the buffer when autocmd_busy is set to FALSE. */
+/* When deleting a buffer/window and autocmd_busy is TRUE, do not free the
+ * buffer/window. but link it in the list starting with
+ * au_pending_free_buf/ap_pending_free_win, using b_next/w_next.
+ * Free the buffer/window when autocmd_busy is being set to FALSE. */
EXTERN buf_T *au_pending_free_buf INIT(= NULL);
+EXTERN win_T *au_pending_free_win INIT(= NULL);
#endif
#ifdef FEAT_MOUSE
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 320,
/**/
319,
/**/
if (wp != aucmd_win)
#endif
win_remove(wp, tp);
- vim_free(wp);
+ if (autocmd_busy)
+ {
+ wp->w_next = au_pending_free_win;
+ au_pending_free_win = wp;
+ }
+ else
+ vim_free(wp);
#ifdef FEAT_AUTOCMD
unblock_autocmds();