Permalink
Browse files

fixed memory leaks

fixed analyze warning "left operand of '-' is a garbage value"
  • Loading branch information...
1 parent 98f80e0 commit bf66bb092f463843eb3b1e239cae5a67330c1fcc @unit51 unit51 committed Aug 16, 2011
Showing with 17 additions and 11 deletions.
  1. +13 −7 Classes/ImageFilter.m
  2. +4 −4 Classes/iphone_filtersViewController.m
View
@@ -47,7 +47,8 @@ - (UIImage*) applyFilter:(FilterCallback)filter context:(void*)context
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
- CGImageRelease(imageRef);
+ CGImageRelease(imageRef);
+ CFRelease(m_DataRef);
return finalImage;
}
@@ -291,7 +292,9 @@ - (UIImage*) applyBlendFilter:(FilterBlendCallback)filter other:(UIImage*)other
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
- CGImageRelease(imageRef);
+ CGImageRelease(imageRef);
+ CFRelease(m_DataRef);
+ CFRelease(m_OtherDataRef);
return finalImage;
}
@@ -437,8 +440,8 @@ void filterLevels(UInt8 *pixelBuf, UInt32 offset, void *context)
assert(xValue <= 255);
assert(xValue >= 0);
- CGPoint point1;
- CGPoint point2;
+ CGPoint point1 = CGPointZero;
+ CGPoint point2 = CGPointZero;
NSInteger idx = 0;
for (idx = 0; idx < equation.length; idx++)
@@ -648,7 +651,9 @@ - (UIImage*) applyConvolve:(NSArray*)kernel
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
- CGImageRelease(imageRef);
+ CGImageRelease(imageRef);
+ CFRelease(m_DataRef);
+ CFRelease(m_OutDataRef);
return finalImage;
}
@@ -807,7 +812,8 @@ - (UIImage*) vignette
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
- CGImageRelease(imageRef);
+ CGImageRelease(imageRef);
+ CFRelease(m_DataRef);
UIImage *mask = [finalImage gaussianBlur:10];
UIImage *blurredSelf = [self gaussianBlur:2];
@@ -863,7 +869,7 @@ - (UIImage*) darkVignette
CGContextRelease(ctx);
UIImage *blackSquare = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
-
+ CFRelease(m_DataRef);
UIImage *maskedSquare = [blackSquare mask:mask];
return [self overlay:[maskedSquare opacity:1.0]];
}
@@ -43,7 +43,7 @@ - (void)viewDidLoad {
- (IBAction) buttonAdjustableClicked:(id)sender
{
// open a dialog with two custom buttons
- self.actionSheetAdjustable = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Set Filter",@"")
+ self.actionSheetAdjustable = [[[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Set Filter",@"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel",@"")
destructiveButtonTitle:nil
@@ -53,7 +53,7 @@ - (IBAction) buttonAdjustableClicked:(id)sender
NSLocalizedString(@"Brightness",@""),
NSLocalizedString(@"Contrast",@""),
NSLocalizedString(@"Gamma",@""),
- nil];
+ nil] autorelease];
self.actionSheetAdjustable.actionSheetStyle = UIActionSheetStyleDefault;
[self.actionSheetAdjustable showInView:self.view]; // show from our table view (pops up in the middle of the table)
}
@@ -62,7 +62,7 @@ - (IBAction) buttonPackagedClicked:(id)sender
{
// open a dialog with two custom buttons
self.actionSheetPackaged =
- [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Apply Filter",@"")
+ [[[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Apply Filter",@"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel",@"")
destructiveButtonTitle:NSLocalizedString(@"Reset",@"")
@@ -72,7 +72,7 @@ - (IBAction) buttonPackagedClicked:(id)sender
NSLocalizedString(@"Lomo",@""),
NSLocalizedString(@"Vignette",@""),
NSLocalizedString(@"Polaroidish",@""),
- nil];
+ nil] autorelease];
self.actionSheetPackaged.actionSheetStyle = UIActionSheetStyleDefault;
[self.actionSheetPackaged showInView:self.view]; // show from our table view (pops up in the middle of the table)

0 comments on commit bf66bb0

Please sign in to comment.