UIImageJPEGRepresentation Memory Leak for CGImage with kCGImageAlphaNone

Originator:bruno
Number:rdar://30073037 Date Originated:18-Jan-2017 01:37 PM
Status:Open Resolved:
Product:iOS Product Version:10.2
Classification:Serious Bug Reproducible:Always
 
Summary:
When using UIImageJPEGRepresentation to get the NSData of a UIImage backed by a CGImage having kCGImageAlphaNone, there is a memory leak.


Steps to Reproduce:
1. Open the attached TestLeak project
2. Run Instruments, and measure leaks. 
3. Observe the leak of the CGImage.

Expected Results:
No leaks.

Actual Results:
A CGImage is leaking.

Notes:
The leak appears when getting the NSData out of a kCGImageAlphaNone buffer. If I change the buffer format to kCGImageAlphaNoneSkipLast, there is no leak (see example project which demonstrate the two versions). However, the documentation claims that these two flags are equivalent: “kCGImageAlphaNone: There is no alpha channel. If the total size of the pixel is greater than the space required for the number of color components in the color space, the least significant bits are ignored. This value is equivalent to kCGImageAlphaNoneSkipLast.”

Based on this, it sounds to me that this is an issue in UIImageJPEGRepresentation where a code path is missing a CGImageRelease. This is also confirmed by the Leaks instruments (see screenshot).

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!