Bug 1462049: Fix MemStream allocation to only allocate its capacity. r=jrmuizel
authorBob Owen <bobowencode@gmail.com>
Wed, 16 May 2018 18:26:24 +0100
changeset 796226 5d99c9233693623ddbb6cd7bc059e8874afca9b6
parent 796225 e016aa76775e0d914bd1caf32fdaaf7fc78de25e
child 796227 29cbfa037517654a34ac44fc957dde2a9c5ea996
child 796279 87690ba7227e86fad4867a49bdcf072963042b3d
push id110183
push userbmo:mh+mozilla@glandium.org
push dateThu, 17 May 2018 09:00:08 +0000
reviewersjrmuizel
bugs1462049
milestone62.0a1
Bug 1462049: Fix MemStream allocation to only allocate its capacity. r=jrmuizel
gfx/2d/RecordedEvent.h
--- a/gfx/2d/RecordedEvent.h
+++ b/gfx/2d/RecordedEvent.h
@@ -188,21 +188,21 @@ struct MemStream {
   char *mData;
   size_t mLength;
   size_t mCapacity;
   void Resize(size_t aSize) {
     mLength = aSize;
     if (mLength > mCapacity) {
       mCapacity = mCapacity * 2;
       // check if the doubled capacity is enough
-      // otherwise use mLength
+      // otherwise use double mLength
       if (mLength > mCapacity) {
-        mCapacity = mLength;
+        mCapacity = mLength * 2;
       }
-      mData = (char*)realloc(mData, mCapacity * 2);
+      mData = (char*)realloc(mData, mCapacity);
     }
   }
 
   void write(const char* aData, size_t aSize) {
     Resize(mLength + aSize);
     memcpy(mData + mLength - aSize, aData, aSize);
   }