Bug 1079848 - Large allocs should be infallible and handled. r=kamidphish, a=bkerensa
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 10 Oct 2014 16:25:07 -0700
changeset 200527 86128ad9d00e87c1494fd557e8bc8b83d87612fa
parent 200526 7ae1b58e84580f25b9964e3aed7a140d485871f8
child 200528 95e4252b6d7477c80757fe5ef5a97e4bf3ea6af2
push id175
push userryanvm@gmail.com
push dateWed, 21 Jan 2015 17:05:19 +0000
treeherdermozilla-esr31@86128ad9d00e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish, bkerensa
bugs1079848
milestone31.4.0
Bug 1079848 - Large allocs should be infallible and handled. r=kamidphish, a=bkerensa
content/canvas/src/WebGLContextGL.cpp
--- a/content/canvas/src/WebGLContextGL.cpp
+++ b/content/canvas/src/WebGLContextGL.cpp
@@ -41,16 +41,17 @@
 #if defined(MOZ_WIDGET_COCOA)
 #include "nsCocoaFeatures.h"
 #endif
 
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/ToJSValue.h"
 #include "mozilla/Endian.h"
+#include "mozilla/fallible.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::gl;
 using namespace mozilla::gfx;
 
 static bool BaseTypeAndSizeFromUniformType(GLenum uType, GLenum *baseType, GLint *unitSize);
 
@@ -3639,17 +3640,22 @@ WebGLContext::TexImage2D_base(GLenum tar
             !mPixelStoreFlipY)
         {
             // no conversion, no flipping, so we avoid copying anything and just pass the source pointer
             pixels = data;
         }
         else
         {
             size_t convertedDataSize = height * dstStride;
-            convertedData = new uint8_t[convertedDataSize];
+            convertedData = (uint8_t*)moz_malloc(convertedDataSize);
+            if (!convertedData) {
+                ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
+                                 " a buffer for doing format conversion.");
+                return;
+            }
             ConvertImage(width, height, srcStride, dstStride,
                         static_cast<uint8_t*>(data), convertedData,
                         actualSrcFormat, srcPremultiplied,
                         dstFormat, mPixelStorePremultiplyAlpha, dstTexelSize);
             pixels = reinterpret_cast<void*>(convertedData.get());
         }
         imageInfoStatusIfSuccess = WebGLImageDataStatus::InitializedImageData;
     }
@@ -3789,17 +3795,22 @@ WebGLContext::TexSubImage2D_base(GLenum 
     // no conversion, no flipping, so we avoid copying anything and just pass the source pointer
     bool noConversion = (actualSrcFormat == dstFormat &&
                          srcPremultiplied == mPixelStorePremultiplyAlpha &&
                          srcStride == dstStride &&
                          !mPixelStoreFlipY);
 
     if (!noConversion) {
         size_t convertedDataSize = height * dstStride;
-        convertedData = new uint8_t[convertedDataSize];
+        convertedData = (uint8_t*)moz_malloc(convertedDataSize);
+        if (!convertedData) {
+            ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
+                             " a buffer for doing format conversion.");
+            return;
+        }
         ConvertImage(width, height, srcStride, dstStride,
                     static_cast<const uint8_t*>(data), convertedData,
                     actualSrcFormat, srcPremultiplied,
                     dstFormat, mPixelStorePremultiplyAlpha, dstTexelSize);
         pixels = reinterpret_cast<void*>(convertedData.get());
     }
 
     GLenum driverType = DriverTypeFromType(gl, type);