aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-03-05 07:09:28 +0800
committerGitHub <noreply@github.com>2023-03-05 07:09:28 +0800
commit39842be8cd8808c7da2638a6cc84d7c3fe40b996 (patch)
tree5607fc342e51de469dd97421f5d9163c2fe7f644 /src
parent7100a80253a353341893e1f6397cc9e07dadbc9d (diff)
downloadrneovim-39842be8cd8808c7da2638a6cc84d7c3fe40b996.tar.gz
rneovim-39842be8cd8808c7da2638a6cc84d7c3fe40b996.tar.bz2
rneovim-39842be8cd8808c7da2638a6cc84d7c3fe40b996.zip
fix(extmarks): don't leak memory on error (#22507)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/extmark.c3
-rw-r--r--src/nvim/decoration.c17
2 files changed, 12 insertions, 8 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 845a4c7dbe..9e03cc8676 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -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;
}
diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c
index c98ffbeefb..7e47565247 100644
--- a/src/nvim/decoration.c
+++ b/src/nvim/decoration.c
@@ -112,15 +112,20 @@ void decor_remove(buf_T *buf, int row, int row2, Decoration *decor)
decor_free(decor);
}
+void decor_clear(Decoration *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) {
- 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);
+ decor_clear(decor);
xfree(decor);
}
}