From 9faee5356cbc615c75d6e57af570bc4be6fda03d Mon Sep 17 00:00:00 2001 From: Nikolaus Heger Date: Fri, 18 Jul 2014 11:07:13 +0700 Subject: [PATCH] guarding against image source == NULL --- SDWebImage/UIImage+MultiFormat.m | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/SDWebImage/UIImage+MultiFormat.m b/SDWebImage/UIImage+MultiFormat.m index 90f55628..45e25962 100644 --- a/SDWebImage/UIImage+MultiFormat.m +++ b/SDWebImage/UIImage+MultiFormat.m @@ -47,20 +47,22 @@ +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { UIImageOrientation result = UIImageOrientationUp; CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); - CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); - if (properties) { - CFTypeRef val; - int exifOrientation; - val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); - if (val) { - CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); - result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; - } // else - if it's not set it remains at up - CFRelease((CFTypeRef) properties); - } else { - //NSLog(@"NO PROPERTIES, FAIL"); + if (imageSource) { + CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); + if (properties) { + CFTypeRef val; + int exifOrientation; + val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); + if (val) { + CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); + result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; + } // else - if it's not set it remains at up + CFRelease((CFTypeRef) properties); + } else { + //NSLog(@"NO PROPERTIES, FAIL"); + } + CFRelease(imageSource); } - CFRelease(imageSource); return result; }