Skip to content

Commit

Permalink
Fixed Xcode 7 analyzer warnings about leaking CGPaths in MDCSwitch.
Browse files Browse the repository at this point in the history
Reviewers: O1 Material components iOS, samnm

Reviewed By: O1 Material components iOS, samnm

Tags: #material_components_ios

Differential Revision: http://codereview.cc/D1674
  • Loading branch information
ajsecord committed Sep 27, 2016
1 parent 7f596f6 commit c2b4b3d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions components/Switch/src/MDCSwitch.m
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,12 @@ + (UIImage *)trackImage {
MDCSwitchIntrinsicSize.width, kSwitchTrackHeight);
CAShapeLayer *layer = [CAShapeLayer layer];
layer.fillColor = [UIColor whiteColor].CGColor;
layer.path = CGPathCreateWithRoundedRect(trackRect, kSwitchTrackHeight / 2,
kSwitchTrackHeight / 2, NULL);

// Local variable used here to avoid analyzer warnings about a potential leak on XCode 7.
CGPathRef path = CGPathCreateWithRoundedRect(trackRect, kSwitchTrackHeight / 2,
kSwitchTrackHeight / 2, NULL);
layer.path = path;
CGPathRelease(path);

UIGraphicsBeginImageContextWithOptions(MDCSwitchIntrinsicSize, NO, 0);
[layer renderInContext:UIGraphicsGetCurrentContext()];
Expand All @@ -471,7 +475,11 @@ + (MDCShadowLayer *)thumbShadowLayer {
layer.rasterizationScale = [UIScreen mainScreen].scale;
layer.shadowMaskEnabled = NO;
[layer setElevation:MDCShadowElevationCardResting];
layer.shadowPath = CGPathCreateWithEllipseInRect(thumbRect, NULL);

// Local variable used here to avoid analyzer warnings about a potential leak on XCode 7.
CGPathRef path = CGPathCreateWithEllipseInRect(thumbRect, NULL);
layer.shadowPath = path;
CGPathRelease(path);

// Unfortunately we can't cache the MDCShadowLayer as an image as CALayer:renderInContext doesn't
// support rendering a layer that consists only of a shadowPath. Rasterizing the layer is a
Expand All @@ -491,7 +499,11 @@ + (UIImage *)thumbImage {
kSwitchThumbRadius * 2, kSwitchThumbRadius * 2);
CAShapeLayer *layer = [[CAShapeLayer alloc] init];
layer.fillColor = [UIColor whiteColor].CGColor;
layer.path = CGPathCreateWithEllipseInRect(thumbRect, NULL);

// Local variable used here to avoid analyzer warnings about a potential leak on XCode 7.
CGPathRef path = CGPathCreateWithEllipseInRect(thumbRect, NULL);
layer.path = path;
CGPathRelease(path);

UIGraphicsBeginImageContextWithOptions(size, NO, 0);
[layer renderInContext:UIGraphicsGetCurrentContext()];
Expand Down

0 comments on commit c2b4b3d

Please sign in to comment.