[PATCH v2 1/2] ui/cocoa: Minor fixes to CALayer based cursors

Phil Dennis-Jordan posted 2 patches 5 months ago
[PATCH v2 1/2] ui/cocoa: Minor fixes to CALayer based cursors
Posted by Phil Dennis-Jordan 5 months ago
This change fixes some object lifetime issues. (Unreleased reference
counts)

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 ui/cocoa.m | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 06ca114800..cca987eac7 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -395,6 +395,13 @@ - (void) dealloc
         CFRelease(eventsTap);
     }
 
+    if (cursor) {
+        cursor_unref(cursor);
+        cursor = NULL;
+    }
+
+    [cursorLayer release];
+    cursorLayer = nil;
     [super dealloc];
 }
 
@@ -474,6 +481,7 @@ - (void)setCursor:(QEMUCursor *)given_cursor
 
     bounds.size.width = cursor->width;
     bounds.size.height = cursor->height;
+    CGColorSpaceRef color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
 
     provider = CGDataProviderCreateWithData(
         NULL,
@@ -488,7 +496,7 @@ - (void)setCursor:(QEMUCursor *)given_cursor
         8, //bitsPerComponent
         32, //bitsPerPixel
         cursor->width * 4, //bytesPerRow
-        CGColorSpaceCreateWithName(kCGColorSpaceSRGB), //colorspace
+        color_space, //colorspace
         kCGBitmapByteOrder32Little | kCGImageAlphaFirst, //bitmapInfo
         provider, //provider
         NULL, //decode
@@ -497,6 +505,7 @@ - (void)setCursor:(QEMUCursor *)given_cursor
     );
 
     CGDataProviderRelease(provider);
+    CGColorSpaceRelease(color_space);
     [CATransaction begin];
     [CATransaction setDisableActions:YES];
     [cursorLayer setBounds:bounds];
-- 
2.39.3 (Apple Git-146)