From 92a6b0113363fc8fc936bdf9f23c171b9bdae862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 5 Jan 2024 13:20:47 +0800 Subject: [PATCH] Brightness (Apple): code optimise and fix mem leaks --- src/detection/brightness/brightness_apple.c | 25 ++++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/detection/brightness/brightness_apple.c b/src/detection/brightness/brightness_apple.c index 4c58b5e6a..52b0cee32 100644 --- a/src/detection/brightness/brightness_apple.c +++ b/src/detection/brightness/brightness_apple.c @@ -61,24 +61,27 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult* if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("DCPAVServiceProxy"), &iterator) != kIOReturnSuccess) return "IOServiceGetMatchingServices() failed"; - FF_STRBUF_AUTO_DESTROY location = ffStrbufCreate(); - io_registry_entry_t registryEntry; while((registryEntry = IOIteratorNext(iterator)) != 0) { - CFMutableDictionaryRef properties; - if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) { - IOObjectRelease(registryEntry); - continue; + FF_CFTYPE_AUTO_RELEASE CFBooleanRef IOAVServiceUserInterfaceSupported = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("IOAVServiceUserInterfaceSupported"), kCFAllocatorDefault, kNilOptions); + if (IOAVServiceUserInterfaceSupported && !CFBooleanGetValue(IOAVServiceUserInterfaceSupported)) + { + // IOAVServiceCreateWithService won't work + IOObjectRelease(registryEntry); + continue; + } } - ffStrbufClear(&location); - if(ffCfDictGetString(properties, CFSTR("Location"), &location) || ffStrbufEqualS(&location, "Embedded")) { - // Builtin display should be handled by DisplayServices - IOObjectRelease(registryEntry); - continue; + FF_CFTYPE_AUTO_RELEASE CFStringRef location = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("Location"), kCFAllocatorDefault, kNilOptions); + if (location && CFStringCompare(location, CFSTR("Embedded"), 0) == 0) + { + // Builtin display should be handled by DisplayServices + IOObjectRelease(registryEntry); + continue; + } } FF_CFTYPE_AUTO_RELEASE IOAVServiceRef service = IOAVServiceCreateWithService(kCFAllocatorDefault, (io_service_t) registryEntry);