neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 295a264b65bd072bf858496e0e5de83d5b1f5ffa
parent 45dc0f3454d826c42efdcd841953b5e7e613bc5e
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Wed, 18 Jan 2023 15:12:45 +0800

fix(statusline): don't leak memory with zero-width click labels

A zero-width click label isn't assigned to any click definition, so its
function name should be freed when filling click definitions.

Diffstat:
Msrc/nvim/statusline.c | 16++++++++++++----
Mtest/functional/ui/statusline_spec.lua | 10++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c @@ -231,8 +231,12 @@ void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_r }; for (int i = 0; click_recs[i].start != NULL; i++) { len += vim_strnsize(buf, (int)(click_recs[i].start - buf)); - while (col < len) { - click_defs[col++] = cur_click_def; + if (col < len) { + while (col < len) { + click_defs[col++] = cur_click_def; + } + } else { + xfree(cur_click_def.func); } buf = (char *)click_recs[i].start; cur_click_def = click_recs[i].def; @@ -242,8 +246,12 @@ void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_r cur_click_def.type = kStlClickDisabled; } } - while (col < width) { - click_defs[col++] = cur_click_def; + if (col < width) { + while (col < width) { + click_defs[col++] = cur_click_def; + } + } else { + xfree(cur_click_def.func); } } diff --git a/test/functional/ui/statusline_spec.lua b/test/functional/ui/statusline_spec.lua @@ -164,6 +164,16 @@ describe('statusline clicks', function() meths.input_mouse('right', 'press', '', 0, 6, 5) eq('0 1 r', eval("g:testvar")) end) + + it('no memory leak with zero-width click labels', function() + command([[ + let &stl = '%@Test@%T%@MyClickFunc@%=%T%@Test@' + ]]) + meths.input_mouse('left', 'press', '', 0, 6, 0) + eq('0 1 l', eval("g:testvar")) + meths.input_mouse('right', 'press', '', 0, 6, 39) + eq('0 1 r', eval("g:testvar")) + end) end) describe('global statusline', function()