Bug 1323847: P3. Don't allocate data for empty buffer. r=gerald. a=gchang
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 16 Dec 2016 16:20:06 +1100
changeset 353149 2e98fec3a9f925a3f313e9d1a20dd03bcc7526ce
parent 353148 432f1e56a9d72ac1708c4b58e69fff969e4441ed
child 353150 5cfa37b18bd779738a1793f83c20d7198b4dceff
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, gchang
bugs1323847
milestone52.0a2
Bug 1323847: P3. Don't allocate data for empty buffer. r=gerald. a=gchang MozReview-Commit-ID: I67RmFZpRDy
dom/media/MediaData.h
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -215,16 +215,20 @@ private:
 
   // Ensure that the backend buffer can hold aLength data. Will update mData.
   // Will enforce that the start of allocated data is always Alignment bytes
   // aligned and that it has sufficient end padding to allow for Alignment bytes
   // block read as required by some data decoders.
   // Returns false if memory couldn't be allocated.
   bool EnsureCapacity(size_t aLength)
   {
+    if (!aLength) {
+      // No need to allocate a buffer yet.
+      return true;
+    }
     const CheckedInt<size_t> sizeNeeded =
       CheckedInt<size_t>(aLength) * sizeof(Type) + AlignmentPaddingSize();
 
     if (!sizeNeeded.isValid() || sizeNeeded.value() >= INT32_MAX) {
       // overflow or over an acceptable size.
       return false;
     }
     if (mData && mCapacity >= sizeNeeded.value()) {