Merge branch 'fix-memory-leak' of https://github.com/Luflosi/kitty

This commit is contained in:
Kovid Goyal
2020-10-26 07:33:06 +05:30

View File

@@ -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;
}