我得到了这个代码:
- (void)saveImageWithData:(NSData*)jpeg andDictionary:(NSDictionary*)dicRef andName:(NSString*)name
{
self.capturedImageName = name;
self.dict = dicRef;
NSLog(@"%@",dicRef);
CGImageSourceRef source ;
source = CGImageSourceCreateWithData((__bridge CFDataRef)jpeg, NULL);
CFStringRef UTI = CGImageSourceGetType(source); //this is the type of image (e.g., public.jpeg)
NSMutableData *dest_data = [NSMutableData data];
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data,UTI,1,NULL);
if(!destination) {
NSLog(@"***Could not create image destination ***");
}
//add the image contained in the image source to the destination, overwriting the old metadata with our modified metadata
CGImageDestinationAddImageFromSource(destination,source,0, (__bridge CFDictionaryRef) dicRef);
//tell the destination to write the image data and metadata into our data object.
//It will return false if something goes wrong
BOOL success = NO;
success = CGImageDestinationFinalize(destination);
if(!success) {
NSLog(@"***Could not create data from image destination ***");
}
//now we have the data ready to go, so do whatever you want with it
//here we just write it to disk at the same path we were passed
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"ARPictures"];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
NSString *fullPath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", name]]; //add our image to the path
[dest_data writeToFile:fullPath atomically:YES];
self.img = [[UIImage alloc] initWithData:dest_data];
self.capturedImageData = [[NSData alloc] initWithData:dest_data];
//cleanup
CFRelease(destination);
CFRelease(source);
}
但是当我运行静态分析器时,它告诉我:
调用 CFRelease 时的空指针参数
但根据我的逻辑,我应该发布由 CGImageDestinationCreateWithData 创建的CGImageSourceRef。
另外我认为释放它可能是一个错误,因为我只是在桥接它,这意味着 arc 仍然控制该对象,因为它最初是一个NSMutableData对象。
更糟糕的是,我读到 CFRelease(Null) 不好。
我非常困惑,任何帮助将不胜感激。
编辑:
好的,我在将指针发送到 CFRelease 之前对指针进行了登录,它们就在那里!
2012-03-03 11:35:34.709 programtest[4821:707] <CGImageDestination 0x331790 [0x3f92d630]>
2012-03-03 11:35:34.723 programtest[4821:707] <CGImageSource 0x33ee80 [0x3f92d630]>
回到最初的问题,为什么静态分析器告诉我我正在发送一个空指针参数?我该如何解决/静音这个?
谢谢
PD:有没有可能我不是发送一个空指针而是一个指向空的指针?