From 6386e29636484ea0cbf19611da078eb50fd85ee0 Mon Sep 17 00:00:00 2001 From: Volodymyr Chernetskyi Date: Fri, 4 Sep 2026 18:37:25 +0200 Subject: [PATCH] fix(api): leaked error message in nvim_eval_statusline() #41690 Problem: `find_window_by_handle()` returns NULL only after `VALIDATE_INT` has already set `err`, so the `api_set_error()` that followed allocated a second message over the first pointer and leaked it. Solution: Drop the redundant call and keep the helper's message, which is already set and better worded. AI-assisted --- src/nvim/api/vim.c | 1 - test/functional/api/vim_spec.lua | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 2d4e12ac53..3b449c06b3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2289,7 +2289,6 @@ DictAs(eval_statusline_ret) nvim_eval_statusline(String str, Dict(eval_statuslin win_T *wp = opts->use_tabline ? curwin : find_window_by_handle(window, err); if (wp == NULL) { - api_set_error(err, kErrorTypeException, "unknown winid %d", window); return result; } diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index ca5a7baeaf..16a2acb0e5 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -4524,6 +4524,12 @@ describe('API', function() }, api.nvim_eval_statusline('%%StatusLineString%#WarningMsg#WithHighlights', {})) end) + it('reports an invalid window once', function() + -- find_window_by_handle() already sets the error, so a second + -- api_set_error() here would allocate a message over that one and leak it. + eq('Invalid window id: 23', pcall_err(api.nvim_eval_statusline, 'a', { winid = 23 })) + end) + it("doesn't exceed maxwidth", function() eq({ str = 'Should be trun>',