fix(macos): harden retained_handle null guard against release-only CFRetain(null) (#80)

Make the retained_handle null check unconditional so release builds no longer risk CFRetain(null); tests keep benign placeholder behavior, production returns ElementNotFound.
This commit is contained in:
Lahfir 2026-06-27 20:14:44 -07:00 committed by GitHub
parent cadbdf9602
commit a708fa0332
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -84,9 +84,11 @@ fn text_len(value: Option<&str>) -> usize {
#[cfg(target_os = "macos")]
fn retained_handle(candidate: AXElement) -> Result<NativeHandle, AdapterError> {
use core_foundation::base::{CFRetain, CFTypeRef};
#[cfg(test)]
if candidate.0.is_null() {
#[cfg(test)]
return Ok(NativeHandle::null());
#[cfg(not(test))]
return Err(AdapterError::element_not_found("element"));
}
unsafe { CFRetain(candidate.0 as CFTypeRef) };
Ok(unsafe { NativeHandle::from_ptr(candidate.0 as *const _) })