Как избежать malloc при использовании CGImageDestinationFinalize

Я пытаюсь программно создать GIF в iOS, используя следующий вопрос стека:

Создать и экспортировать анимированный GIF через iOS?

Мой код выглядит так:

 // File Parameters
const void *keys[] =   { kCGImagePropertyGIFLoopCount };
const void *values[] = { (CFNumberRef) 0 };

CFDictionaryRef params          = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
const void *keys2[] =   { kCGImagePropertyGIFDictionary };
const void *values2[] = { (CFDictionaryRef) params  };

CFDictionaryRef fileProperties  = CFDictionaryCreate(NULL, keys2 , values2, 1, NULL, NULL);

// URL to the documents directory
NSURL *documentsDirectoryURL  = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
NSURL *fileURL                = [documentsDirectoryURL URLByAppendingPathComponent:fileName];

// Object that writes GIF to the specified URL
CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)fileURL, kUTTypeGIF, [arrayOfAllFrames count], NULL);
CGImageDestinationSetProperties(destination, fileProperties);

for (NSUInteger i = 0; i < [arrayOfAllFrames count]; i++) {
    @autoreleasepool {
        float delayTime = [[gifFramesDuration objectAtIndex:i] floatValue]; 
        NSDictionary *frameProperties = @{
                                          (__bridge id)kCGImagePropertyGIFDictionary: @{
                                                  (__bridge id)kCGImagePropertyGIFDelayTime: [NSNumber numberWithFloat:delayTime] // a float (not double!) in seconds, rounded to centiseconds in the GIF data
                                                  }
                                          };

        UIImage *myImage = [arrayOfAllFrames objectAtIndex:i];
        CGImageDestinationAddImage(destination, myImage.CGImage, (__bridge CFDictionaryRef)frameProperties);
    }
}
if (!CGImageDestinationFinalize(destination)) {
    NSLog(@"failed to finalize image destination");
}
CFRelease(destination);
CFRelease(fileProperties);
CFRelease(params);

Однако, как только я пытаюсь добавить около 240 кадров в файл GIF, отладчик выдает следующую ошибку после вызова CGImageDestinationFinalize:

(923,0xb0115000) malloc: *** error for object 0xd1e7204: incorrect checksum for freed object - object was probably modified after being freed.

Не могли бы вы предоставить мне какой-нибудь обходной путь или предложение о том, как избежать malloc?

Ответы на вопрос(1)

Ваш ответ на вопрос