From b03ada82837a3d967bb0f22be7a3a21871bec518 Mon Sep 17 00:00:00 2001 From: Anthony Eid Date: Tue, 16 Dec 2025 16:51:32 -0500 Subject: [PATCH] Fix get_device_name memory leak by using CFRetained for device name I would've used CFRelease, but that isn't a public function. CFRetained calls CFRelease under the hood when it's dropped, so this is the next best thing. I noticed this leak when running instruments on Zed, please let me know if I missed anything. --- src/audio_unit/macos_helpers.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/audio_unit/macos_helpers.rs b/src/audio_unit/macos_helpers.rs index c29951c30..56ae5b368 100644 --- a/src/audio_unit/macos_helpers.rs +++ b/src/audio_unit/macos_helpers.rs @@ -30,7 +30,7 @@ use objc2_core_audio::{ AudioObjectSetPropertyData, AudioStreamRangedDescription, }; use objc2_core_audio_types::{AudioBufferList, AudioStreamBasicDescription, AudioValueRange}; -use objc2_core_foundation::CFString; +use objc2_core_foundation::{CFRetained, CFString}; use crate::audio_unit::audio_format::{AudioFormat, LinearPcmFlags}; use crate::audio_unit::sample_format::SampleFormat; @@ -290,8 +290,9 @@ pub fn get_device_name(device_id: AudioDeviceID) -> Result { NonNull::from(&mut device_name).cast(), ); try_status_or_return!(status); - - Ok((&*device_name).to_string()) + let device_name = NonNull::new(device_name as *mut CFString).ok_or(Error::Unknown(0))?; + let device_name = CFRetained::from_raw(device_name); + Ok(device_name.to_string()) } }