Skip to content

Commit

Permalink
Fabric: fix border memory leaks (#23815)
Browse files Browse the repository at this point in the history
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: #23815

Differential Revision: D14431250

Pulled By: shergin

fbshipit-source-id: dc663c633ae24809cb4841800d31a6ac6eeb8aa5
  • Loading branch information
ericlewis authored and facebook-github-bot committed Mar 13, 2019
1 parent 10d2842 commit 8e490d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -396,7 +398,9 @@ - (void)invalidateLayer
}

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;
Expand Down
8 changes: 7 additions & 1 deletion React/Fabric/RCTConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8e490d4

Please sign in to comment.