diff options
-rw-r--r-- | src/nvim/quickfix.c | 14 | ||||
-rw-r--r-- | test/old/testdir/test_quickfix.vim | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 5f197bc84f..aca70d1195 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1745,10 +1745,24 @@ static void wipe_qf_buffer(qf_info_T *qi) buf_T *const qfbuf = buflist_findnr(qi->qf_bufnr); if (qfbuf != NULL && qfbuf->b_nwindows == 0) { + bool buf_was_null = false; + // can happen when curwin is going to be closed e.g. curwin->w_buffer + // was already closed in win_close(), and we are now closing the + // window related location list buffer from win_free_mem() + // but close_buffer() calls CHECK_CURBUF() macro and requires + // curwin->w_buffer == curbuf + if (curwin->w_buffer == NULL) { + curwin->w_buffer = curbuf; + buf_was_null = true; + } + // If the quickfix buffer is not loaded in any window, then // wipe the buffer. close_buffer(NULL, qfbuf, DOBUF_WIPE, false, false); qi->qf_bufnr = INVALID_QFBUFNR; + if (buf_was_null) { + curwin->w_buffer = NULL; + } } } diff --git a/test/old/testdir/test_quickfix.vim b/test/old/testdir/test_quickfix.vim index ca48812e7d..0d2dd24e0a 100644 --- a/test/old/testdir/test_quickfix.vim +++ b/test/old/testdir/test_quickfix.vim @@ -6596,4 +6596,12 @@ func Test_hardlink_fname() call Xtest_hardlink_fname('l') endfunc +func Test_quickfix_close_buffer_crash() + new + lexpr 'test' | lopen + wincmd k + lclose + wincmd q +endfunc + " vim: shiftwidth=2 sts=2 expandtab |