summaryrefslogtreecommitdiffstats
path: root/src/ex_cmds.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-15 16:22:52 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-15 16:22:52 +0100
commit797e63b9f2baa1853e7063aac478d663cd02f207 (patch)
tree9fa8b1f0922ac19e98e0db47736c5e8107801317 /src/ex_cmds.c
parent17d015b2438e51d4d42d72720611d16c772cc4bb (diff)
patch 8.2.2354: crash with a weird combination of autocommandsv8.2.2354
Problem: Crash with a weird combination of autocommands. Solution: Increment b_nwindows when needed. (closes #7674)
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r--src/ex_cmds.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 24763d94d3..a3226d25cf 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2742,6 +2742,8 @@ do_ecmd(
else
{
win_T *the_curwin = curwin;
+ int did_decrement;
+ buf_T *was_curbuf = curbuf;
// Set the w_closing flag to avoid that autocommands close the
// window. And set b_locked for the same reason.
@@ -2754,7 +2756,7 @@ do_ecmd(
// Close the link to the current buffer. This will set
// oldwin->w_buffer to NULL.
u_sync(FALSE);
- close_buffer(oldwin, curbuf,
+ did_decrement = close_buffer(oldwin, curbuf,
(flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE, FALSE);
the_curwin->w_closing = FALSE;
@@ -2776,7 +2778,15 @@ do_ecmd(
goto theend;
}
if (buf == curbuf) // already in new buffer
+ {
+ // close_buffer() has decremented the window count,
+ // increment it again here and restore w_buffer.
+ if (did_decrement && buf_valid(was_curbuf))
+ ++was_curbuf->b_nwindows;
+ if (win_valid_any_tab(oldwin) && oldwin->w_buffer == NULL)
+ oldwin->w_buffer = was_curbuf;
auto_buf = TRUE;
+ }
else
{
#ifdef FEAT_SYN_HL