From f6929ea51d21034c6ed00d68a727c2c7cd7ec6ac Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Tue, 17 Jan 2023 02:51:01 +0100 Subject: [PATCH] fix(tabline): avoid memory leak in tabline click definitions (#21847) Problem: Memory is leaked in tabline click definitions since https://github.com/neovim/neovim/pull/21008. Solution: Add back a call to `stl_clear_click_defs()` that was lost in the refactor PR. --- src/nvim/statusline.c | 4 ++++ test/functional/ui/tabline_spec.lua | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index 3171ee1605..e0c531859c 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -733,6 +733,10 @@ void draw_tabline(void) return; } + // Clear tab_page_click_defs: Clicking outside of tabs has no effect. + assert(tab_page_click_defs_size >= (size_t)Columns); + stl_clear_click_defs(tab_page_click_defs, tab_page_click_defs_size); + // Use the 'tabline' option if it's set. if (*p_tal != NUL) { win_redr_custom(NULL, false, false); diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua index 0e35a03557..2cdec62d01 100644 --- a/test/functional/ui/tabline_spec.lua +++ b/test/functional/ui/tabline_spec.lua @@ -119,4 +119,10 @@ describe("tabline", function() [2] = {bold = true, foreground = Screen.colors.Blue}; }} end) + + it('click definitions do not leak memory #21765', function() + command('set tabline=%@MyClickFunc@MyClickText%T') + command('set showtabline=2') + command('redrawtabline') + end) end)