Skip to content

Commit

Permalink
Cocoa: Fix potential leak of CFNumber object
Browse files Browse the repository at this point in the history
Spotted by Clang static analysis.

(cherry picked from commit a2674a9)
  • Loading branch information
elmindreda committed Sep 2, 2020
1 parent 2a5ac9a commit b8a6254
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions src/cocoa_monitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b8a6254

Please sign in to comment.