Title: [174665] trunk/Source/WebCore
Revision
174665
Author
[email protected]
Date
2014-10-13 16:46:20 -0700 (Mon, 13 Oct 2014)

Log Message

[Mac] Return value of createImageSourceOptions() is leaked in ImageSourceCG
https://bugs.webkit.org/show_bug.cgi?id=137677

Reviewed by Simon Fraser.

The return value of createImageSourceOptions() was leaked in
ImageSourceCG.cpp. It was returning a CFDictionaryRef created using
CFDictionaryCreate(). Therefore, the return value should have been
released but wasn't.

This patch makes createImageSourceOptions() return a
RetainPtr<CFDictionaryRef> to make sure the CFDictionaryRef properly
gets released after use.

No new tests, no behavior change.

* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::createImageSourceOptions):
(WebCore::imageSourceOptions):
(WebCore::ImageSource::isSizeAvailable):
(WebCore::ImageSource::allowSubsamplingOfFrameAtIndex):
(WebCore::ImageSource::frameSizeAtIndex):
(WebCore::ImageSource::orientationAtIndex):
(WebCore::ImageSource::getHotSpot):
(WebCore::ImageSource::repetitionCount):
(WebCore::ImageSource::createFrameAtIndex):
(WebCore::ImageSource::frameDurationAtIndex):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174664 => 174665)


--- trunk/Source/WebCore/ChangeLog	2014-10-13 23:10:20 UTC (rev 174664)
+++ trunk/Source/WebCore/ChangeLog	2014-10-13 23:46:20 UTC (rev 174665)
@@ -1,3 +1,33 @@
+2014-10-13  Chris Dumez  <[email protected]>
+
+        [Mac] Return value of createImageSourceOptions() is leaked in ImageSourceCG
+        https://bugs.webkit.org/show_bug.cgi?id=137677
+
+        Reviewed by Simon Fraser.
+
+        The return value of createImageSourceOptions() was leaked in
+        ImageSourceCG.cpp. It was returning a CFDictionaryRef created using
+        CFDictionaryCreate(). Therefore, the return value should have been
+        released but wasn't.
+
+        This patch makes createImageSourceOptions() return a
+        RetainPtr<CFDictionaryRef> to make sure the CFDictionaryRef properly
+        gets released after use.
+
+        No new tests, no behavior change.
+
+        * platform/graphics/cg/ImageSourceCG.cpp:
+        (WebCore::createImageSourceOptions):
+        (WebCore::imageSourceOptions):
+        (WebCore::ImageSource::isSizeAvailable):
+        (WebCore::ImageSource::allowSubsamplingOfFrameAtIndex):
+        (WebCore::ImageSource::frameSizeAtIndex):
+        (WebCore::ImageSource::orientationAtIndex):
+        (WebCore::ImageSource::getHotSpot):
+        (WebCore::ImageSource::repetitionCount):
+        (WebCore::ImageSource::createFrameAtIndex):
+        (WebCore::ImageSource::frameDurationAtIndex):
+
 2014-10-13  Yusuke Suzuki  <[email protected]>
 
         CSS JIT: Implement :visited pseudo class

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp (174664 => 174665)


--- trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp	2014-10-13 23:10:20 UTC (rev 174664)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp	2014-10-13 23:46:20 UTC (rev 174665)
@@ -34,12 +34,13 @@
 #include "IntSize.h"
 #include "MIMETypeRegistry.h"
 #include "SharedBuffer.h"
+#include <wtf/NeverDestroyed.h>
+
 #if !PLATFORM(IOS)
 #include <ApplicationServices/ApplicationServices.h>
 #else
 #include <CoreGraphics/CGImagePrivate.h>
 #include <ImageIO/ImageIO.h>
-#include <wtf/NeverDestroyed.h>
 #include <wtf/RetainPtr.h>
 #endif
 
@@ -106,7 +107,7 @@
         setData(data, allDataReceived);
 }
 
-static CFDictionaryRef createImageSourceOptions(SubsamplingLevel subsamplingLevel)
+static RetainPtr<CFDictionaryRef> createImageSourceOptions(SubsamplingLevel subsamplingLevel)
 {
     if (!subsamplingLevel) {
         const unsigned numOptions = 3;
@@ -122,15 +123,15 @@
     const CFIndex numOptions = 4;
     const void* keys[numOptions] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32, kCGImageSourceSkipMetadata, kCGImageSourceSubsampleFactor };
     const void* values[numOptions] = { kCFBooleanTrue, kCFBooleanTrue, kCFBooleanTrue, subsampleNumber.get() };
-    return CFDictionaryCreate(nullptr, keys, values, numOptions, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+    return adoptCF(CFDictionaryCreate(nullptr, keys, values, numOptions, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
 }
 
-static CFDictionaryRef imageSourceOptions(SubsamplingLevel subsamplingLevel = 0)
+static RetainPtr<CFDictionaryRef> imageSourceOptions(SubsamplingLevel subsamplingLevel = 0)
 {
     if (subsamplingLevel)
         return createImageSourceOptions(subsamplingLevel);
 
-    static CFDictionaryRef options = createImageSourceOptions(0);
+    static NeverDestroyed<RetainPtr<CFDictionaryRef>> options = createImageSourceOptions(0);
     return options;
 }
 
@@ -185,7 +186,7 @@
 
     // Ragnaros yells: TOO SOON! You have awakened me TOO SOON, Executus!
     if (imageSourceStatus >= kCGImageStatusIncomplete) {
-        RetainPtr<CFDictionaryRef> image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions()));
+        RetainPtr<CFDictionaryRef> image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions().get()));
         if (image0Properties) {
             CFNumberRef widthNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelWidth);
             CFNumberRef heightNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelHeight);
@@ -210,7 +211,7 @@
 
 bool ImageSource::allowSubsamplingOfFrameAtIndex(size_t) const
 {
-    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions()));
+    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions().get()));
     if (!properties)
         return false;
 
@@ -232,7 +233,7 @@
 
 IntSize ImageSource::frameSizeAtIndex(size_t index, SubsamplingLevel subsamplingLevel, ImageOrientationDescription description) const
 {
-    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions(subsamplingLevel)));
+    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions(subsamplingLevel).get()));
 
     if (!properties)
         return IntSize();
@@ -254,7 +255,7 @@
 
 ImageOrientation ImageSource::orientationAtIndex(size_t index) const
 {
-    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions()));
+    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions().get()));
     if (!properties)
         return DefaultImageOrientation;
 
@@ -268,7 +269,7 @@
 
 bool ImageSource::getHotSpot(IntPoint& hotSpot) const
 {
-    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions()));
+    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions().get()));
     if (!properties)
         return false;
 
@@ -304,7 +305,7 @@
     if (!initialized())
         return cAnimationLoopOnce;
 
-    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyProperties(m_decoder, imageSourceOptions()));
+    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyProperties(m_decoder, imageSourceOptions().get()));
     if (!properties)
         return cAnimationLoopOnce;
 
@@ -348,7 +349,7 @@
     if (!initialized())
         return 0;
 
-    RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions(subsamplingLevel)));
+    RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions(subsamplingLevel).get()));
 
 #if PLATFORM(IOS)
     // <rdar://problem/7371198> - CoreGraphics changed the default caching behaviour in iOS 4.0 to kCGImageCachingTransient
@@ -391,7 +392,7 @@
         return 0;
 
     float duration = 0;
-    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions()));
+    RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions().get()));
     if (properties) {
         CFDictionaryRef gifProperties = (CFDictionaryRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyGIFDictionary);
         if (gifProperties) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to