diff options
-rw-r--r-- | src/nvim/quickfix.c | 9 | ||||
-rw-r--r-- | src/nvim/window.c | 4 | ||||
-rw-r--r-- | test/functional/viml/errorlist_spec.lua | 13 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index dfd38a6eca..0785fa703d 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3617,6 +3617,15 @@ static int qf_open_new_cwindow(qf_info_T *qi, int height) if (win_split(height, flags) == FAIL) { return FAIL; // not enough room for window } + + // User autocommands may have invalidated the previous window after calling + // win_split, so add a check to ensure that the win is still here + if (IS_LL_STACK(qi) && !win_valid(win)) { + // close the window that was supposed to be for the loclist + win_close(curwin, false); + return FAIL; + } + RESET_BINDING(curwin); if (IS_LL_STACK(qi)) { diff --git a/src/nvim/window.c b/src/nvim/window.c index fd7af108b7..859f4353b3 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -1301,6 +1301,10 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) p_wh = i; } + if (!win_valid(oldwin)) { + return FAIL; + } + // Send the window positions to the UI oldwin->w_pos_changed = true; diff --git a/test/functional/viml/errorlist_spec.lua b/test/functional/viml/errorlist_spec.lua index 9acc61e398..077d816903 100644 --- a/test/functional/viml/errorlist_spec.lua +++ b/test/functional/viml/errorlist_spec.lua @@ -68,4 +68,17 @@ describe('setloclist()', function() command('lclose | wincmd w | lopen') eq('foo', get_cur_win_var('quickfix_title')) end) + + it("doesn't crash when when window is closed in the middle #13721", function() + helpers.insert([[ + hello world]]) + + command("vsplit") + command("autocmd WinLeave * :call nvim_win_close(0, v:true)") + + command("call setloclist(0, [])") + command("lopen") + + helpers.assert_alive() + end) end) |