Bug 1045977 - Clear heap allocated volatile buffers. r=njn, r=seth, a=sledru
authorMichael Wu <mwu@mozilla.com>
Tue, 19 Aug 2014 15:30:55 -0400
changeset 208348 bff13e7445c5
parent 208347 023ef0541072
child 208349 342c0c26e18d
push id3835
push userryanvm@gmail.com
push date2014-08-20 22:04 +0000
treeherdermozilla-beta@54949d681a14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn, seth, sledru
bugs1045977
milestone32.0
Bug 1045977 - Clear heap allocated volatile buffers. r=njn, r=seth, a=sledru
image/src/imgFrame.cpp
memory/mozalloc/VolatileBuffer.h
--- a/image/src/imgFrame.cpp
+++ b/image/src/imgFrame.cpp
@@ -174,16 +174,21 @@ nsresult imgFrame::Init(int32_t aX, int3
       NS_WARNING("Exceed the hard limit of decode image size");
       return NS_ERROR_OUT_OF_MEMORY;
     }
     if (!mImageSurface) {
       mVBuf = AllocateBufferForImage(mSize, mFormat);
       if (!mVBuf) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
+      if (mVBuf->OnHeap()) {
+        int32_t stride = VolatileSurfaceStride(mSize, mFormat);
+        VolatileBufferPtr<uint8_t> ptr(mVBuf);
+        memset(ptr, 0, stride * mSize.height);
+      }
       mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
     }
 
     if (!mImageSurface) {
       NS_WARNING("Failed to create VolatileDataSourceSurface");
       // Image surface allocation is failed, need to return
       // the booked buffer size.
       DiscardTracker::InformDeallocation(4 * mSize.width * mSize.height);
--- a/memory/mozalloc/VolatileBuffer.h
+++ b/memory/mozalloc/VolatileBuffer.h
@@ -51,21 +51,21 @@ public:
   VolatileBuffer();
   ~VolatileBuffer();
 
   /* aAlignment must be a multiple of the pointer size */
   bool Init(size_t aSize, size_t aAlignment = sizeof(void*));
 
   size_t HeapSizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
   size_t NonHeapSizeOfExcludingThis() const;
+  bool OnHeap() const;
 
 protected:
   bool Lock(void** aBuf);
   void Unlock();
-  bool OnHeap() const;
 
 private:
   void* mBuf;
   size_t mSize;
   int mLockCount;
 #if defined(ANDROID)
   int mFd;
 #elif defined(XP_DARWIN)