From f459472f6d38751dc385f1197b7279afdb07df4c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 7 Aug 2021 03:46:08 +0200 Subject: [PATCH] Fix leaks - we were not honoring the ownership policy/create rule for various CoreFoundation functions with 'Copy' or 'Create' in the title --- frontend/drivers/platform_darwin.m | 8 ++++++++ input/drivers_hid/iohidmanager_hid.c | 1 + 2 files changed, 9 insertions(+) diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index a5b01fb67e..e0cd1368fd 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -156,8 +156,13 @@ static void CFSearchPathForDirectoriesInDomains(unsigned flags, CFArrayRef array = array_val ? CFRetain(array_val) : NULL; CFTypeRef path_val = (CFTypeRef)CFArrayGetValueAtIndex(array, 0); CFStringRef path = path_val ? CFRetain(path_val) : NULL; + CFRelease(array_val); if (!path || !array) + { + if (path) + CFRelease(path); return; + } CFStringGetCString(path, s, len, kCFStringEncodingUTF8); CFRelease(path); @@ -370,10 +375,13 @@ static void frontend_darwin_get_env(int *argc, char *argv[], resource_url = CFBundleCopyResourcesDirectoryURL(bundle); resource_path = CFURLCopyPath(resource_url); + CFRelease(resource_url); + CFStringGetCString(bundle_path, bundle_path_buf, sizeof(bundle_path_buf), kCFStringEncodingUTF8); CFStringGetCString(resource_path, resource_path_buf, sizeof(resource_path_buf), kCFStringEncodingUTF8); + CFRelease(resource_path); fill_pathname_join(full_resource_path_buf, bundle_path_buf, resource_path_buf, sizeof(full_resource_path_buf)); CFSearchPathForDirectoriesInDomains(CFDocumentDirectory, CFUserDomainMask, 1, home_dir_buf, sizeof(home_dir_buf)); diff --git a/input/drivers_hid/iohidmanager_hid.c b/input/drivers_hid/iohidmanager_hid.c index c5e0f8f518..2e580eed27 100644 --- a/input/drivers_hid/iohidmanager_hid.c +++ b/input/drivers_hid/iohidmanager_hid.c @@ -1010,6 +1010,7 @@ static int iohidmanager_hid_manager_set_device_matching( CFIndex num_devices = CFSetGetCount(set); IOHIDDeviceRef *device_array = (IOHIDDeviceRef*)calloc(num_devices, sizeof(IOHIDDeviceRef)); CFSetGetValues(set, (const void **) device_array); + CFRelease(set); /* re order device by location id */ typedef struct hid_list