From b8a6254a2643b23e989e256a6fbd07f1f2ac6ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 23 Jul 2020 18:55:29 +0200 Subject: [PATCH] Cocoa: Fix potential leak of CFNumber object Spotted by Clang static analysis. (cherry picked from commit a2674a903434b7dfc0b0bcc5d0b479da417367ff) --- README.md | 2 ++ src/cocoa_monitor.m | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 263d63e7..00d7804b 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,8 @@ information on what to include when reporting a bug. - [Cocoa] Changed `EGLNativeWindowType` from `NSView` to `CALayer` (#1169) - [Cocoa] Bugfix: Non-BMP Unicode codepoint input was reported as UTF-16 (#1635) + - [Cocoa] Bugfix: Failing to retrieve the refresh rate of built-in displays + could leak memory - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 8ef94a3b..cc45f85e 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -277,14 +277,20 @@ static double getFallbackRefreshRate(CGDirectDisplayID displayID) CFSTR("IOFBCurrentPixelCount"), kCFAllocatorDefault, kNilOptions); - if (!clockRef || !countRef) - break; uint32_t clock = 0, count = 0; - CFNumberGetValue(clockRef, kCFNumberIntType, &clock); - CFNumberGetValue(countRef, kCFNumberIntType, &count); - CFRelease(clockRef); - CFRelease(countRef); + + if (clockRef) + { + CFNumberGetValue(clockRef, kCFNumberIntType, &clock); + CFRelease(clockRef); + } + + if (countRef) + { + CFNumberGetValue(countRef, kCFNumberIntType, &count); + CFRelease(countRef); + } if (clock > 0 && count > 0) refreshRate = clock / (double) count;