guarding against image source == NULL
Showing
1 changed file
with
15 additions
and
13 deletions
@@ -47,20 +47,22 @@ | @@ -47,20 +47,22 @@ | ||
47 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { | 47 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { |
48 | UIImageOrientation result = UIImageOrientationUp; | 48 | UIImageOrientation result = UIImageOrientationUp; |
49 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); | 49 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); |
50 | - CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); | ||
51 | - if (properties) { | ||
52 | - CFTypeRef val; | ||
53 | - int exifOrientation; | ||
54 | - val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); | ||
55 | - if (val) { | ||
56 | - CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); | ||
57 | - result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; | ||
58 | - } // else - if it's not set it remains at up | ||
59 | - CFRelease((CFTypeRef) properties); | ||
60 | - } else { | ||
61 | - //NSLog(@"NO PROPERTIES, FAIL"); | 50 | + if (imageSource) { |
51 | + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); | ||
52 | + if (properties) { | ||
53 | + CFTypeRef val; | ||
54 | + int exifOrientation; | ||
55 | + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); | ||
56 | + if (val) { | ||
57 | + CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); | ||
58 | + result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; | ||
59 | + } // else - if it's not set it remains at up | ||
60 | + CFRelease((CFTypeRef) properties); | ||
61 | + } else { | ||
62 | + //NSLog(@"NO PROPERTIES, FAIL"); | ||
63 | + } | ||
64 | + CFRelease(imageSource); | ||
62 | } | 65 | } |
63 | - CFRelease(imageSource); | ||
64 | return result; | 66 | return result; |
65 | } | 67 | } |
66 | 68 |
-
Please register or login to post a comment