Bug 985017 - Part 1: Support null VolatileBufferPtrs. r=glandium, a=1.4+
authorMichael Wu <mwu@mozilla.com>
Wed, 02 Apr 2014 21:32:54 -0400
changeset 191522 1266d70f29514d9b55b9ed9b8376d311e3891346
parent 191521 e277c405f06608811e058d09caa104696210cca4
child 191523 60c9101d530466d7f108a3e52023450c910dc97b
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium, 1
bugs985017
milestone30.0a2
Bug 985017 - Part 1: Support null VolatileBufferPtrs. r=glandium, a=1.4+
memory/mozalloc/VolatileBuffer.h
--- a/memory/mozalloc/VolatileBuffer.h
+++ b/memory/mozalloc/VolatileBuffer.h
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozalloc_VolatileBuffer_h
 #define mozalloc_VolatileBuffer_h
 
 #include "mozilla/mozalloc.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/NullPtr.h"
 
 /* VolatileBuffer
  *
  * This class represents a piece of memory that can potentially be reclaimed
  * by the OS when not in use. As long as there are one or more
  * VolatileBufferPtrs holding on to a VolatileBuffer, the memory will remain
  * available. However, when there are no VolatileBufferPtrs holding a
  * VolatileBuffer, the OS can purge the pages if it wants to. The OS can make
@@ -73,21 +74,28 @@ private:
   bool mHeap;
   bool mFirstLock;
 #endif
 };
 
 class VolatileBufferPtr_base {
 public:
   VolatileBufferPtr_base(VolatileBuffer* vbuf) : mVBuf(vbuf) {
-    mPurged = !vbuf->Lock(&mMapping);
+    if (vbuf) {
+      mPurged = !vbuf->Lock(&mMapping);
+    } else {
+      mMapping = nullptr;
+      mPurged = false;
+    }
   }
 
   ~VolatileBufferPtr_base() {
-    mVBuf->Unlock();
+    if (mVBuf) {
+      mVBuf->Unlock();
+    }
   }
 
   bool WasBufferPurged() const {
     return mPurged;
   }
 
 protected:
   void* mMapping;