neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 960cba7b3bf9d8987171a703c4587b79aaea4321
parent eb5a7cc0ddf07a29b2c8c9c68ff50321dece845f
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sat, 17 Jan 2026 18:35:41 +0800

vim-patch:9.1.2090: Last buffer not freed with EXITFREE

Problem:  Last buffer not freed with EXITFREE (after 9.1.2087).
Solution: Free the last buffer when inside free_all_mem()
          (zeertzjq).

This isn't really a memory leak, as the last buffer's memory is still
reachable via pointers like firstbuf and lastbuf. But it's possible that
this may cause false ASAN warnings in the future, which is what EXITFREE
is supposed to prevent.

closes: vim/vim#19194

https://github.com/vim/vim/commit/6c118afeaae756f3bbb9793e6b248517ad39a3aa

Diffstat:
Msrc/nvim/buffer.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c @@ -719,15 +719,20 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last, bool i // Autocommands may have opened or closed windows for this buffer. // Decrement the count for the close we do here. // Don't decrement b_nwindows if the buffer wasn't displayed in any window - // before calling buf_freeall(), + // before calling buf_freeall(). if (nwindows > 0 && buf->b_nwindows > 0) { buf->b_nwindows--; } // Remove the buffer from the list. // Do not wipe out the buffer if it is used in a window, or if autocommands - // wiped out all other buffers. - if (wipe_buf && buf->b_nwindows <= 0 && (buf->b_prev != NULL || buf->b_next != NULL)) { + // wiped out all other buffers (unless when inside free_all_mem() where all + // buffers need to be freed and autocommands are blocked). + if (wipe_buf && buf->b_nwindows <= 0 && (buf->b_prev != NULL || buf->b_next != NULL +#if defined(EXITFREE) + || entered_free_all_mem +#endif + )) { if (clear_w_buf) { win->w_buffer = NULL; }