Skip to content

Commit 3cea4d6

Browse files
authored
Merge pull request #18942 from neovim/backport-18933-to-release-0.7
[Backport release-0.7] fix(buffer): disable buffer-updates before removing buffer from window
2 parents 1dba6cf + 05f6883 commit 3cea4d6

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/nvim/buffer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,10 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last, bool i
578578
return false;
579579
}
580580

581+
// Disable buffer-updates for the current buffer.
582+
// No need to check `unload_buf`: in that case the function returned above.
583+
buf_updates_unload(buf, false);
584+
581585
if (win != NULL // Avoid bogus clang warning.
582586
&& win_valid_any_tab(win)
583587
&& win->w_buffer == buf) {
@@ -590,10 +594,6 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last, bool i
590594
buf->b_nwindows--;
591595
}
592596

593-
// Disable buffer-updates for the current buffer.
594-
// No need to check `unload_buf`: in that case the function returned above.
595-
buf_updates_unload(buf, false);
596-
597597
// Remove the buffer from the list.
598598
if (wipe_buf) {
599599
// Do not wipe out the buffer if it is used in a window.

src/nvim/window.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7207,7 +7207,7 @@ void win_findbuf(typval_T *argvars, list_T *list)
72077207
int bufnr = tv_get_number(&argvars[0]);
72087208

72097209
FOR_ALL_TAB_WINDOWS(tp, wp) {
7210-
if (!wp->w_closing && wp->w_buffer->b_fnum == bufnr) {
7210+
if (wp->w_buffer->b_fnum == bufnr) {
72117211
tv_list_append_number(list, wp->handle);
72127212
}
72137213
}

test/functional/lua/buffer_updates_spec.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,28 @@ describe('lua buffer event callbacks: on_lines', function()
252252
eq(2, meths.win_get_cursor(0)[1])
253253
end)
254254

255-
it('does not SEGFAULT when calling win_findbuf in on_detach', function()
256-
257-
exec_lua[[
255+
it('does not SEGFAULT when accessing window buffer info in on_detach #14998', function()
256+
local code = [[
258257
local buf = vim.api.nvim_create_buf(false, false)
259258
260259
vim.cmd"split"
261260
vim.api.nvim_win_set_buf(0, buf)
262261
263262
vim.api.nvim_buf_attach(buf, false, {
264263
on_detach = function(_, buf)
264+
vim.fn.tabpagebuflist()
265265
vim.fn.win_findbuf(buf)
266266
end
267267
})
268268
]]
269269

270+
exec_lua(code)
270271
command("q!")
271272
helpers.assert_alive()
273+
274+
exec_lua(code)
275+
command("bd!")
276+
helpers.assert_alive()
272277
end)
273278

274279
it('#12718 lnume', function()

0 commit comments

Comments
 (0)