From 72ac9ac9a1085d6f9bba64e49dd5afd500199aef Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Jan 2026 11:32:52 +0800 Subject: [PATCH] fix(terminal): possible memory leak on exit (#37532) Problem: On exit, it's possible that term_delayed_free() hasn't been called yet when the main loop is freed, in which case it won't be called ever. Solution: Don't bail out with term->destroy set when calling terminal_close() inside free_all_mem(). --- src/nvim/terminal.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index c985665b4f..0047a8c789 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -583,9 +583,6 @@ void terminal_close(Terminal **termpp, int status) FUNC_ATTR_NONNULL_ALL { Terminal *term = *termpp; - if (term->destroy) { - return; - } #ifdef EXITFREE if (entered_free_all_mem) { @@ -596,6 +593,10 @@ void terminal_close(Terminal **termpp, int status) } #endif + if (term->destroy) { // Destruction already scheduled on the main loop. + return; + } + bool only_destroy = false; if (term->closed) {