[BlackBerry] ImageBuffer::copyImage leaking memory
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Apr 2013 15:00:56 +0000 (15:00 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Apr 2013 15:00:56 +0000 (15:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=115359

Patch by Mike Lattanzio <mlattanzio@blackberry.com> on 2013-04-30
Reviewed by George Staikos.

Use a WebCore::Vector to ensure the temporary data is destroyed.
The TiledImage does not take ownership of the data.

* platform/graphics/blackberry/ImageBufferBlackBerry.cpp:
(WebCore::ImageBuffer::copyImage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@149370 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/blackberry/ImageBufferBlackBerry.cpp

index 40a143e..2455b23 100644 (file)
@@ -1,3 +1,16 @@
+2013-04-30  Mike Lattanzio  <mlattanzio@blackberry.com>
+
+        [BlackBerry] ImageBuffer::copyImage leaking memory
+        https://bugs.webkit.org/show_bug.cgi?id=115359
+
+        Reviewed by George Staikos.
+
+        Use a WebCore::Vector to ensure the temporary data is destroyed.
+        The TiledImage does not take ownership of the data.
+
+        * platform/graphics/blackberry/ImageBufferBlackBerry.cpp:
+        (WebCore::ImageBuffer::copyImage):
+
 2013-04-30  Noam Rosenthal  <noam@webkit.org>
 
         [Texmap] Avoid using overlap/non-overlap region in cases where the overhead is bigger than the gain
index e061faa..372a4c0 100644 (file)
@@ -32,6 +32,7 @@
 #include <BlackBerryPlatformGraphicsContext.h>
 #include <BlackBerryPlatformSettings.h>
 #include <BlackBerryPlatformWindow.h>
+#include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
 using namespace std;
@@ -210,10 +211,10 @@ PlatformLayer* ImageBuffer::platformLayer() const
 PassRefPtr<Image> ImageBuffer::copyImage(BackingStoreCopy, ScaleBehavior) const
 {
     // FIXME respect copyBehaviour enum.
-    unsigned* imageData = new unsigned[m_size.width() * m_size.height()];
-    m_data.getImageData(m_context.get(), IntRect(IntPoint(0, 0), m_size), IntRect(IntPoint(0, 0), m_size), (unsigned char*)imageData, false /* unmultiply */);
-    BlackBerry::Platform::Graphics::TiledImage* nativeImage = new BlackBerry::Platform::Graphics::TiledImage(m_size, imageData, false /* dataIsBGRA */);
-    return BitmapImage::create(nativeImage);
+    Vector<unsigned> pixels;
+    pixels.reserveCapacity(m_size.area());
+    m_data.getImageData(m_context.get(), IntRect(IntPoint(0, 0), m_size), IntRect(IntPoint(0, 0), m_size), reinterpret_cast<unsigned char*>(pixels.data()), false /* unmultiply */);
+    return BitmapImage::create(new BlackBerry::Platform::Graphics::TiledImage(m_size, pixels.data(), false /* dataIsBGRA */));
 }
 
 void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const