diff --git a/WebpQuickLook/GeneratePreviewForURL.c b/WebpQuickLook/GeneratePreviewForURL.c index 59f44bd..6d8e71b 100644 --- a/WebpQuickLook/GeneratePreviewForURL.c +++ b/WebpQuickLook/GeneratePreviewForURL.c @@ -20,17 +20,20 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, // get posix path and convert it to C string then we can get data from file with simple C operation. // Sometimes CoreFoundation is pain in the ass. I don't want to use it to get byte data - CFStringRef path = CFURLCopyPath(url); - path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, path, CFSTR("")); + CFStringRef rawPath = CFURLCopyPath(url); + CFStringRef path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, rawPath, CFSTR("")); + CFRelease(rawPath); CFIndex length = CFStringGetLength(path); CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); char* c_path = (char*)malloc(maxSize); CFStringGetCString(path, c_path, maxSize, kCFStringEncodingUTF8); + CFRelease(path); // let 's do the reading and decoding with libwebp FILE *file = fopen(c_path, "r"); + free(c_path); if (file != NULL) { @@ -121,11 +124,15 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, rgbData, width*height*samples, NULL); - CGImageRef image = CGImageCreate(width, height, 8, 8 * samples, width * samples, CGColorSpaceCreateDeviceRGB(), bitmapInfo, provider, NULL, false, kCGRenderingIntentDefault); - + CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB(); + CGImageRef image = CGImageCreate(width, height, 8, 8 * samples, width * samples, deviceRGBColorSpace, bitmapInfo, provider, NULL, false, kCGRenderingIntentDefault); CGContextDrawImage(ctx, CGRectMake(0, 0, width, height), image); + CGDataProviderRelease(provider); + CGColorSpaceRelease(deviceRGBColorSpace); + CGImageRelease(image); + CGContextFlush(ctx); QLPreviewRequestFlushContext(preview, ctx); diff --git a/WebpQuickLook/GenerateThumbnailForURL.c b/WebpQuickLook/GenerateThumbnailForURL.c index 8d9efba..dc93d7a 100644 --- a/WebpQuickLook/GenerateThumbnailForURL.c +++ b/WebpQuickLook/GenerateThumbnailForURL.c @@ -19,17 +19,20 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum // get posix path and convert it to C string then we can get data from file with simple C operation. // Sometimes CoreFoundation is pain in the ass. I don't want to use it to get byte data - CFStringRef path = CFURLCopyPath(url); - path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, path, CFSTR("")); + CFStringRef rawPath = CFURLCopyPath(url); + CFStringRef path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, rawPath, CFSTR("")); + CFRelease(rawPath); CFIndex length = CFStringGetLength(path); CFIndex max = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); char* c_path = (char*)malloc(max); CFStringGetCString(path, c_path, max, kCFStringEncodingUTF8); + CFRelease(path); // let 's do the reading and decoding with libwebp FILE *file = fopen(c_path, "r"); + free(c_path); if (file != NULL) { @@ -128,11 +131,15 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, rgbData, width*height*4, NULL); - CGImageRef image = CGImageCreate(width, height, 8, 32, width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaLast, provider, NULL, false, kCGRenderingIntentDefault); - + CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB(); + CGImageRef image = CGImageCreate(width, height, 8, 32, width * 4, deviceRGBColorSpace, kCGImageAlphaLast, provider, NULL, false, kCGRenderingIntentDefault); CGContextDrawImage(ctx, CGRectMake(0, 0, width, height), image); + CGDataProviderRelease(provider); + CGColorSpaceRelease(deviceRGBColorSpace); + CGImageRelease(image); + CGContextFlush(ctx); QLThumbnailRequestFlushContext(thumbnail, ctx);