From 6f844cf1a1a18e25b70fcdf1bcdc458555bd2eff Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Thu, 15 Jan 2026 16:38:44 -0500 Subject: [PATCH] Fix `get_descriptors` memory leak (#746) This function incorrectly assumed that `CTFontCollectionCreateMatchingFontDescriptors` doesn't follow the *Create* rule which is false. From Apple's docs > A retained reference to an array of normalized font descriptors matching the collection definition. https://leopard-adc.pepas.com/documentation/Carbon/Reference/CTFontCollectionRef/Reference/reference.html#//apple_ref/c/func/CTFontCollectionCreateMatchingFontDescriptors I also confirmed using instruments that this was causing a memory leak in Zed. --- core-text/src/font_collection.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core-text/src/font_collection.rs b/core-text/src/font_collection.rs index 5103e8a..dda043c 100644 --- a/core-text/src/font_collection.rs +++ b/core-text/src/font_collection.rs @@ -38,15 +38,13 @@ impl_CFTypeDescription!(CTFontCollection); impl CTFontCollection { pub fn get_descriptors(&self) -> Option> { - // surprise! this function follows the Get rule, despite being named *Create*. - // So we have to addRef it to avoid CTFontCollection from double freeing it later. unsafe { let font_descriptors = CTFontCollectionCreateMatchingFontDescriptors(self.0); if font_descriptors.is_null() { // This returns null if there are no matching font descriptors. None } else { - Some(CFArray::wrap_under_get_rule(font_descriptors)) + Some(CFArray::wrap_under_create_rule(font_descriptors)) } } }