aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-20 10:05:02 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-04-21 19:07:50 +0800
commit1664e3d4bcc122e6a3b064a3fe20fdc163f6ae9d (patch)
tree050c5e32274e2b9c4bfb69fda5cdeb5b3e07ba00 /src/nvim/window.c
parent407be5975db5dd63671397676eef0279662c603d (diff)
downloadrneovim-1664e3d4bcc122e6a3b064a3fe20fdc163f6ae9d.tar.gz
rneovim-1664e3d4bcc122e6a3b064a3fe20fdc163f6ae9d.tar.bz2
rneovim-1664e3d4bcc122e6a3b064a3fe20fdc163f6ae9d.zip
vim-patch:8.2.2476: using freed memory when splitting window while closing buffer
Problem: Using freed memory when using an autocommand to split a window while a buffer is being closed. Solution: Disallow splitting when the buffer has b_locked_split set. https://github.com/vim/vim/commit/983d83ff1cd796ff321074335fa53fbe7ac45a46 Put the error message in window.c. Cherry-pick a memory leak fix from Vim patch 8.2.0399. Test still fails.
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index d1cc5f245a..f68cfe4c9c 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -72,6 +72,9 @@ typedef enum {
WEE_TRIGGER_LEAVE_AUTOCMDS = 0x10,
} wee_flags_T;
+static char e_cannot_split_window_when_closing_buffer[]
+ = N_("E1159: Cannot split a window when closing the buffer");
+
static char *m_onlyone = N_("Already only one window");
/// When non-zero splitting a window is forbidden. Used to avoid that nasty
@@ -946,6 +949,10 @@ static int check_split_disallowed(void)
emsg(_("E242: Can't split a window while closing another"));
return FAIL;
}
+ if (curwin->w_buffer->b_locked_split) {
+ emsg(_(e_cannot_split_window_when_closing_buffer));
+ return FAIL;
+ }
return OK;
}
@@ -966,6 +973,10 @@ static int check_split_disallowed(void)
*/
int win_split(int size, int flags)
{
+ if (check_split_disallowed() == FAIL) {
+ return FAIL;
+ }
+
// When the ":tab" modifier was used open a new tab page instead.
if (may_open_tabpage() == OK) {
return OK;
@@ -977,9 +988,6 @@ int win_split(int size, int flags)
emsg(_("E442: Can't split topleft and botright at the same time"));
return FAIL;
}
- if (check_split_disallowed() == FAIL) {
- return FAIL;
- }
// When creating the help window make a snapshot of the window layout.
// Otherwise clear the snapshot, it's now invalid.