From 35f7388725ac0192c7d9b1468b5189ce751c8099 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sun, 25 Oct 2020 16:31:57 +0100 Subject: [PATCH] Fix memory leaks in coretext_all_fonts() Found with the Clang Static Analyzer. --- kitty/core_text.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kitty/core_text.m b/kitty/core_text.m index 5606df8ed..51eec2c81 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -161,12 +161,13 @@ coretext_all_fonts(PyObject UNUSED *_self) { CFArrayRef matches = CTFontCollectionCreateMatchingFontDescriptors(all_fonts_collection()); const CFIndex count = CFArrayGetCount(matches); PyObject *ans = PyTuple_New(count), *temp; - if (ans == NULL) return PyErr_NoMemory(); + if (ans == NULL) { CFRelease(matches); return PyErr_NoMemory(); } for (CFIndex i = 0; i < count; i++) { temp = font_descriptor_to_python((CTFontDescriptorRef) CFArrayGetValueAtIndex(matches, i)); - if (temp == NULL) { Py_DECREF(ans); return NULL; } + if (temp == NULL) { CFRelease(matches); Py_DECREF(ans); return NULL; } PyTuple_SET_ITEM(ans, i, temp); temp = NULL; } + CFRelease(matches); return ans; }