Bug 1284032 - Fix an assertion in SourceBuffer::Compact() when we have non-zero capacity but zero length. r=edwin
authorSeth Fowler <mark.seth.fowler@gmail.com>
Sat, 02 Jul 2016 23:18:25 -0600
changeset 346238 98eca6a35e1a96107aba99410afb256bdb2dd6cd
parent 346237 0a64cf8e2fb51ab0fe81bf0bb154caf2e5848d93
child 346239 07a67db040dca1ae3722eed0cd36880dd66da73b
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1284032
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1284032 - Fix an assertion in SourceBuffer::Compact() when we have non-zero capacity but zero length. r=edwin
image/SourceBuffer.cpp
--- a/image/SourceBuffer.cpp
+++ b/image/SourceBuffer.cpp
@@ -133,16 +133,23 @@ SourceBuffer::Compact()
   }
 
   // We can compact our buffer. Determine the total length.
   size_t length = 0;
   for (uint32_t i = 0 ; i < mChunks.Length() ; ++i) {
     length += mChunks[i].Length();
   }
 
+  // If our total length is zero (which means ExpectLength() got called, but no
+  // data ever actually got written) then just empty our chunk list.
+  if (MOZ_UNLIKELY(length == 0)) {
+    mChunks.Clear();
+    return NS_OK;
+  }
+
   Maybe<Chunk> newChunk = CreateChunk(length, /* aRoundUp = */ false);
   if (MOZ_UNLIKELY(!newChunk || newChunk->AllocationFailed())) {
     NS_WARNING("Failed to allocate chunk for SourceBuffer compacting - OOM?");
     return NS_OK;
   }
 
   // Copy our old chunks into the new chunk.
   for (uint32_t i = 0 ; i < mChunks.Length() ; ++i) {