mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
fix(extmarks): don't leak memory on error (#22507)
This commit is contained in:
parent
7100a80253
commit
39842be8cd
@ -809,8 +809,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
||||
return (Integer)id;
|
||||
|
||||
error:
|
||||
clear_virttext(&decor.virt_text);
|
||||
xfree(decor.sign_text);
|
||||
decor_clear(&decor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -112,15 +112,20 @@ void decor_remove(buf_T *buf, int row, int row2, Decoration *decor)
|
||||
decor_free(decor);
|
||||
}
|
||||
|
||||
void decor_free(Decoration *decor)
|
||||
void decor_clear(Decoration *decor)
|
||||
{
|
||||
if (decor) {
|
||||
clear_virttext(&decor->virt_text);
|
||||
for (size_t i = 0; i < kv_size(decor->virt_lines); i++) {
|
||||
clear_virttext(&kv_A(decor->virt_lines, i).line);
|
||||
}
|
||||
kv_destroy(decor->virt_lines);
|
||||
xfree(decor->sign_text);
|
||||
}
|
||||
|
||||
void decor_free(Decoration *decor)
|
||||
{
|
||||
if (decor) {
|
||||
decor_clear(decor);
|
||||
xfree(decor);
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,13 @@ describe('API/extmarks', function()
|
||||
eq("Invalid 'id': expected positive Integer", pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 }))
|
||||
eq("Invalid mark position: expected 2 Integer items", pcall_err(get_extmarks, ns, {}, {-1, -1}))
|
||||
eq("Invalid mark position: expected mark id Integer or 2-item Array", pcall_err(get_extmarks, ns, true, {-1, -1}))
|
||||
-- No memory leak with virt_text, virt_lines, sign_text
|
||||
eq("right_gravity is not a boolean", pcall_err(set_extmark, ns, marks[2], 0, 0, {
|
||||
virt_text = {{'foo', 'Normal'}},
|
||||
virt_lines = {{{'bar', 'Normal'}}},
|
||||
sign_text = 'a',
|
||||
right_gravity = 'baz',
|
||||
}))
|
||||
end)
|
||||
|
||||
it("can end extranges past final newline using end_col = 0", function()
|
||||
|
Loading…
Reference in New Issue
Block a user