From b233f71b1bd688363d3efd8f550dbf44cc4e841c Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Wed, 25 Mar 2026 10:47:12 +0000 Subject: [PATCH] fix: :ball w_locked check, reset b_nwindows in free_all_mem() #38484 Problem: - Small error in port of v9.1.0678, causing :ball to check w_locked for the wrong window. - After #27439, free_all_mem() may not wipe out buffers that were open in more than one window before windows were freed. Solution: - Check win_locked() for wp in ex_buffer_all(), not curwin. - Set b_nwindows to 0 in free_all_mem() before calling close_buffer(). Ref: https://github.com/neovim/neovim/pull/38473#issuecomment-4125117681 No need to block these fixes on that. free_all_mem() change also looks like it fixed the existing "N lua references were leaked!" warnings on the CI. --- src/nvim/buffer.c | 2 +- src/nvim/memory.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 94f327726d..8f83686f4e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3663,7 +3663,7 @@ void ex_buffer_all(exarg_T *eap) : wp->w_width != Columns) || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW - && !(win_locked(curwin) || wp->w_buffer->b_locked > 0) + && !(win_locked(wp) || wp->w_buffer->b_locked > 0) && !is_aucmd_win(wp)) { if (win_close(wp, false, false) == FAIL) { break; diff --git a/src/nvim/memory.c b/src/nvim/memory.c index ec82848138..50062122e8 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -950,6 +950,8 @@ void free_all_mem(void) bufref_T bufref; set_bufref(&bufref, buf); nextbuf = buf->b_next; + // All windows were freed. Reset b_nwindows so buffers can be wiped. + buf->b_nwindows = 0; // Since options (in addition to other stuff) have been freed above we need to ensure no // callbacks are called, so free them before closing the buffer.