From fa69cac7e315f85bf5a6fe16795c65ea51046a8d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 11 May 2026 21:07:39 +0800 Subject: [PATCH] fix(terminal): memory leak when pasting '=' register (#39738) Problem: Memory leak when pasting '=' register in terminal. Solution: Free the register. (cherry picked from commit 41e8201c6c43e582cde33526091142655de5d0d8) --- src/nvim/register.c | 6 ++++-- test/functional/terminal/buffer_spec.lua | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/nvim/register.c b/src/nvim/register.c index e6e8401f26..5887f921d0 100644 --- a/src/nvim/register.c +++ b/src/nvim/register.c @@ -1470,7 +1470,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) if (curbuf->terminal) { terminal_paste(count, y_array, y_size); - return; + goto end; } colnr_T split_pos = 0; @@ -2076,7 +2076,9 @@ end: xfree(y_array); } - VIsual_active = false; + if (!curbuf->terminal) { // XXX + VIsual_active = false; + } // If the cursor is past the end of the line put it at the end. adjust_cursor_eol(); diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 63e0272874..42a6685c70 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -123,6 +123,14 @@ describe(':terminal buffer', function() appended tty ready |*5 | ]]) + -- pasting expression register shouldn't leak memory + feed([["="abcd\nefghi"pi]]) + screen:expect([[ + appended tty ready |*4 + abcd | + efghi^ | + {5:-- TERMINAL --} | + ]]) end) it('sends data to the terminal when the ":put" command is used', function()