1

私はこのコードを手に入れました:

- (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をリリースする必要があります

また、ブリッジしているだけなので、リリースするのは間違いかもしれないと思っています。つまり、元々はNSMutableDataオブジェクトであったため、arcはそのオブジェクトを引き続き制御します。

さらに悪いことに、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]>

では、元の質問に戻ると、静的アナライザーがnullポインター引数を送信していることをどのように通知するのでしょうか。これを修正/ミュートするにはどうすればよいですか?

ありがとう

PD:nullポインターではなく、nullへのポインターを送信している可能性はありますか?

4

2 に答える 2

6

NULLを渡すと、CFReleaseがクラッシュするため、アナライザーは、宛先とソースがNULLである可能性があることを警告します。NULLのチェックを追加するだけです。

if ( destination != NULL )
    CFRelease(destination);

if ( source != NULL )
    CFRelease(source);
于 2012-03-03T03:06:56.973 に答える
0

静的アナライザーが示しているのは、引数の1つがnullになる可能性があるということです。

たとえば、後に返品を行う場合

NSLog(@"***Could not create image destination ***");

警告は止まりますか?

于 2012-03-03T02:48:10.090 に答える