commit 72ac9ac9a1085d6f9bba64e49dd5afd500199aef
parent 813a6d3b1128fa8bc54fcc7e0468991bee47d11f
Author: zeertzjq <zeertzjq@outlook.com>
Date: Sat, 24 Jan 2026 11:32:52 +0800
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().
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git 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) {