fix(statusline): don't leak memory with truncated click labels

This commit is contained in:
zeertzjq
2023-01-18 19:10:58 +08:00
parent 295a264b65
commit 01ddc09747
2 changed files with 13 additions and 0 deletions

View File

@@ -1987,6 +1987,11 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
// the truncation point
for (int i = 0; i < itemcnt; i++) {
if (stl_items[i].start > trunc_p) {
for (int j = i; j < itemcnt; j++) {
if (stl_items[j].type == ClickFunc) {
XFREE_CLEAR(stl_items[j].cmd);
}
}
itemcnt = i;
break;
}

View File

@@ -174,6 +174,14 @@ describe('statusline clicks', function()
meths.input_mouse('right', 'press', '', 0, 6, 39)
eq('0 1 r', eval("g:testvar"))
end)
it('no memory leak with truncated click labels', function()
command([[
let &stl = '%@MyClickFunc@foo%X' .. repeat('a', 40) .. '%<t%@Test@bar%X%@Test@baz'
]])
meths.input_mouse('left', 'press', '', 0, 6, 2)
eq('0 1 l', eval("g:testvar"))
end)
end)
describe('global statusline', function()