From 47748c7935540014abed03b4d2ff809b471c4fe3 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Fri, 4 Oct 2024 03:56:30 -0700 Subject: [PATCH] fix(iOS): Properly retain/release backgroundColor in RCTBorderDrawing (#46797) Summary: I discovered this while working on my shim of `UIGraphicsImageRenderer` for macOS (See https://github.com/microsoft/react-native-macos/pull/2209). A variable of type`CGColorRef` is not automatically retained and released when passed into a block. There was a case in `RCTBorderDrawing` where we were doing so. To fix this, we have two options: 1. Pass a `UIColor` instead (Requires a change to the signature of the function calling it) 2. Properly retain and release the variable. The first option would technically be a breaking change (we would need to change the signature of `RCTGetBorderImage`, so I'm opting for option 2. ## Changelog: [IOS] [FIXED] - Properly retain/release backgroundColor in RCTBorderDrawing Pull Request resolved: https://github.com/facebook/react-native/pull/46797 Test Plan: CI should pass. Locally, borders still draw fine for me. Reviewed By: joevilches Differential Revision: D63827824 Pulled By: cipolleschi fbshipit-source-id: 926601d062b90a7d741d7a1af3070cec4b8795ae --- packages/react-native/React/Views/RCTBorderDrawing.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native/React/Views/RCTBorderDrawing.m b/packages/react-native/React/Views/RCTBorderDrawing.m index 86c15d1e4c7..67bf10cba93 100644 --- a/packages/react-native/React/Views/RCTBorderDrawing.m +++ b/packages/react-native/React/Views/RCTBorderDrawing.m @@ -232,6 +232,8 @@ static UIImage *RCTGetSolidBorderImage( UIGraphicsImageRenderer *const imageRenderer = RCTMakeUIGraphicsImageRenderer(size, backgroundColor, hasCornerRadii, drawToEdge); + + CGColorRetain(backgroundColor); UIImage *image = [imageRenderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) { const CGContextRef context = rendererContext.CGContext; const CGRect rect = {.size = size}; @@ -242,6 +244,7 @@ static UIImage *RCTGetSolidBorderImage( CGContextAddPath(context, path); CGContextFillPath(context); } + CGColorRelease(backgroundColor); CGContextAddPath(context, path); CGPathRelease(path);