Fabric: fix border memory leaks (#23815)

Summary:
This fixes a few memory leaks in fabrics handling of colors for borders, when using CGColorRef's we must be diligent about releasing the memory back.

[iOS] [Fixed] - Border style memory leaks
Pull Request resolved: https://github.com/facebook/react-native/pull/23815

Differential Revision: D14431250

Pulled By: shergin

fbshipit-source-id: dc663c633ae24809cb4841800d31a6ac6eeb8aa5
This commit is contained in:
ericlewis
2019-03-12 19:57:31 -07:00
committed by Facebook Github Bot
parent 10d28421cf
commit 8e490d4d87
2 changed files with 16 additions and 6 deletions

View File

@@ -326,10 +326,12 @@ static RCTCornerRadii RCTCornerRadiiFromBorderRadii(BorderRadii borderRadii)
static RCTBorderColors RCTBorderColorsFromBorderColors(BorderColors borderColors)
{
return RCTBorderColors{.left = RCTCGColorRefFromSharedColor(borderColors.left),
.top = RCTCGColorRefFromSharedColor(borderColors.top),
.bottom = RCTCGColorRefFromSharedColor(borderColors.bottom),
.right = RCTCGColorRefFromSharedColor(borderColors.right)};
return RCTBorderColors{
.left = RCTCGColorRefUnretainedFromSharedColor(borderColors.left),
.top = RCTCGColorRefUnretainedFromSharedColor(borderColors.top),
.bottom = RCTCGColorRefUnretainedFromSharedColor(borderColors.bottom),
.right = RCTCGColorRefUnretainedFromSharedColor(borderColors.right)
};
}
static UIEdgeInsets UIEdgeInsetsFromBorderInsets(EdgeInsets edgeInsets)
@@ -396,7 +398,9 @@ static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle)
}
layer.borderWidth = (CGFloat)borderMetrics.borderWidths.left;
layer.borderColor = RCTCGColorRefFromSharedColor(borderMetrics.borderColors.left);
CGColorRef borderColor = RCTCGColorRefFromSharedColor(borderMetrics.borderColors.left);
layer.borderColor = borderColor;
CGColorRelease(borderColor);
layer.cornerRadius = (CGFloat)borderMetrics.borderRadii.topLeft;
layer.backgroundColor = _backgroundColor.CGColor;
_contentView.layer.cornerRadius = (CGFloat)borderMetrics.borderRadii.topLeft;

View File

@@ -30,7 +30,13 @@ inline UIColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::Share
return sharedColor ? [UIColor colorWithCGColor:sharedColor.get()] : nil;
}
inline CGColorRef RCTCGColorRefFromSharedColor(const facebook::react::SharedColor &sharedColor) {
inline CF_RETURNS_NOT_RETAINED CGColorRef RCTCGColorRefUnretainedFromSharedColor(const facebook::react::SharedColor &sharedColor) {
return sharedColor ? sharedColor.get() : nil;
}
inline CF_RETURNS_RETAINED CGColorRef RCTCGColorRefFromSharedColor(const facebook::react::SharedColor &sharedColor) {
return sharedColor ? CGColorCreateCopy(sharedColor.get()) : nil;
}