I am tracking down a strange bug. The bug manifests itself with the display of this message in the console log:
BlurApp(5018,0xa00d6500) malloc: *** error for object 0x103b000: pointer being freed was not allocated
This message pops in after execution has left my event loop. It seems to be happening when the autorelease pool is being drained. Here is the code that seems to trigger the error:
- (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
I call imageWithImage this way:
UIImage* theImage = [self imageWithImage:origImage scaledToSize:rect.size];
theImage is used in the calling routine and then I assume autorelease will take care of it.
If I change the return newImage;
to return [newImage retain];
the error message is not seen.
Now, here is what is very strange. This error only occurs with certain sizes of newSize. specifically, it always happens when newSize's height and width are equal to any number in the range of 55 to 176 excluding 56, 110, 112, 114, and not for other values of height and width between 5 and 300. (height and width are always equal for all tests)
I could use some fresh eyes on this... thanks!