<https://bugs.webkit.org/show_bug.cgi?id=62666>
[WebKit-https.git] / Source / WebKit2 / Shared / API / c / cg / WKImageCG.cpp
index 7af747e219118c7f6e50be4b4eb96fccd562b1be..87663115b4360e2f8bdc41c200daf02d0578b82a 100644 (file)
@@ -36,13 +36,26 @@ using namespace WebCore;
 
 CGImageRef WKImageCreateCGImage(WKImageRef imageRef)
 {
 
 CGImageRef WKImageCreateCGImage(WKImageRef imageRef)
 {
-    return toImpl(imageRef)->bitmap()->makeCGImageCopy().leakRef();
+    if (!imageRef)
+        return 0;
+    
+    WebImage* webImage = toImpl(imageRef);
+    if (!webImage || !webImage->bitmap())
+        return 0;
+    
+    return webImage->bitmap()->makeCGImageCopy().leakRef();
 }
 
 WKImageRef WKImageCreateFromCGImage(CGImageRef imageRef, WKImageOptions options)
 {
 }
 
 WKImageRef WKImageCreateFromCGImage(CGImageRef imageRef, WKImageOptions options)
 {
+    if (!imageRef)
+        return 0;
+    
     IntSize imageSize(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
     RefPtr<WebImage> webImage = WebImage::create(imageSize, toImageOptions(options));
     IntSize imageSize(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
     RefPtr<WebImage> webImage = WebImage::create(imageSize, toImageOptions(options));
+    if (!webImage || !webImage->bitmap())
+        return 0;
+    
     OwnPtr<GraphicsContext> graphicsContext = webImage->bitmap()->createGraphicsContext();
     CGContextDrawImage(graphicsContext->platformContext(), CGRectMake(0, 0, imageSize.width(), imageSize.height()), imageRef);
     return toAPI(webImage.release().leakRef());
     OwnPtr<GraphicsContext> graphicsContext = webImage->bitmap()->createGraphicsContext();
     CGContextDrawImage(graphicsContext->platformContext(), CGRectMake(0, 0, imageSize.width(), imageSize.height()), imageRef);
     return toAPI(webImage.release().leakRef());