Title: [264034] trunk/Source/WebCore
Revision
264034
Author
[email protected]
Date
2020-07-07 12:17:31 -0700 (Tue, 07 Jul 2020)

Log Message

Fix potential pixel buffer leak in ImageRotationSessionVT::rotate
https://bugs.webkit.org/show_bug.cgi?id=213922

Reviewed by Eric Carlson.

Fix a potential memory leak in an error case.
Add more logging to be able to see errors.
Remove the kCVPixelBufferIOSurfacePropertiesKey key on iOS from the buffer pool to revert
part of https://trac.webkit.org/changeset/258504/webkit that seems problematic in iOS.

* platform/graphics/cv/ImageRotationSessionVT.mm:
(WebCore::ImageRotationSessionVT::initialize):
(WebCore::ImageRotationSessionVT::rotate):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264033 => 264034)


--- trunk/Source/WebCore/ChangeLog	2020-07-07 18:59:43 UTC (rev 264033)
+++ trunk/Source/WebCore/ChangeLog	2020-07-07 19:17:31 UTC (rev 264034)
@@ -1,3 +1,19 @@
+2020-07-07  Youenn Fablet  <[email protected]>
+
+        Fix potential pixel buffer leak in ImageRotationSessionVT::rotate
+        https://bugs.webkit.org/show_bug.cgi?id=213922
+
+        Reviewed by Eric Carlson.
+
+        Fix a potential memory leak in an error case.
+        Add more logging to be able to see errors.
+        Remove the kCVPixelBufferIOSurfacePropertiesKey key on iOS from the buffer pool to revert
+        part of https://trac.webkit.org/changeset/258504/webkit that seems problematic in iOS.
+
+        * platform/graphics/cv/ImageRotationSessionVT.mm:
+        (WebCore::ImageRotationSessionVT::initialize):
+        (WebCore::ImageRotationSessionVT::rotate):
+
 2020-07-07  Simon Fraser  <[email protected]>
 
         Unable to scroll elcomerico.pe page until the page finishes loading

Modified: trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm (264033 => 264034)


--- trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm	2020-07-07 18:59:43 UTC (rev 264033)
+++ trunk/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm	2020-07-07 19:17:31 UTC (rev 264034)
@@ -27,6 +27,7 @@
 #import "ImageRotationSessionVT.h"
 
 #import "AffineTransform.h"
+#import "Logging.h"
 #import "MediaSample.h"
 
 #import "CoreVideoSoftLink.h"
@@ -94,22 +95,35 @@
         (__bridge NSString *)kCVPixelBufferHeightKey: @(m_rotatedSize.height()),
         (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(pixelFormat),
         (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: (cvImageCompatibility == IsCGImageCompatible::Yes ? @YES : @NO),
+#if PLATFORM(IOS_SIMULATOR) || PLATFORM(MAC)
         (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
+#endif
     };
     CVPixelBufferPoolRef rawPool = nullptr;
     if (auto err = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &rawPool); err != noErr)
-        LOG_ERROR("CVPixelBufferPool create returned error code %d", err);
+        RELEASE_LOG_ERROR(WebRTC, "ImageRotationSessionVT failed creating buffer pool with error %d", err);
     m_rotationPool = adoptCF(rawPool);
 }
 
 RetainPtr<CVPixelBufferRef> ImageRotationSessionVT::rotate(CVPixelBufferRef pixelBuffer)
 {
+    RetainPtr<CVPixelBufferRef> result;
+
     CVPixelBufferRef rawRotatedBuffer = nullptr;
-    CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_rotationPool.get(), &rawRotatedBuffer);
-    auto status = VTImageRotationSessionTransferImage(m_rotationSession.get(), pixelBuffer, rawRotatedBuffer);
-    if (status == noErr)
-        return adoptCF(rawRotatedBuffer);
-    return nullptr;
+    auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_rotationPool.get(), &rawRotatedBuffer);
+    if (status != kCVReturnSuccess) {
+        RELEASE_LOG_ERROR(WebRTC, "ImageRotationSessionVT failed creating buffer from pool with error %d", status);
+        return nullptr;
+    }
+    result = adoptCF(rawRotatedBuffer);
+
+    status = VTImageRotationSessionTransferImage(m_rotationSession.get(), pixelBuffer, rawRotatedBuffer);
+    if (status != noErr) {
+        RELEASE_LOG_ERROR(WebRTC, "ImageRotationSessionVT failed rotating buffer with error %d", status);
+        return nullptr;
+    }
+
+    return result;
 }
 
 RetainPtr<CVPixelBufferRef> ImageRotationSessionVT::rotate(MediaSample& sample, const RotationProperties& rotation, IsCGImageCompatible cvImageCompatibility)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to