Bug 1366208 - Make sure no empty RefPtr are ever stored. r=gerald, a=gchang
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 19 May 2017 11:55:16 +0200
changeset 394044 5de3b1528ca0947dfde7b1aef7a42f5984b5ee89
parent 394043 eac1fd1b0c992cb1124d438fe1be37972ccabc4d
child 394045 64096bfc5a89e6c92911a3257fdca0f169418022
push id7339
push userryanvm@gmail.com
push dateMon, 22 May 2017 18:17:11 +0000
treeherdermozilla-beta@5de3b1528ca0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, gchang
bugs1366208
milestone54.0
Bug 1366208 - Make sure no empty RefPtr are ever stored. r=gerald, a=gchang Should any error occurred while checking the tracks, we could end up with a null pointer stored in the list of track demuxers. MozReview-Commit-ID: 13FllESrpbg
dom/media/fmp4/MP4Demuxer.cpp
--- a/dom/media/fmp4/MP4Demuxer.cpp
+++ b/dom/media/fmp4/MP4Demuxer.cpp
@@ -142,38 +142,38 @@ MP4Demuxer::Init()
   if (audioTrackCount == 0 && videoTrackCount == 0) {
     return InitPromise::CreateAndReject(
       MediaResult(NS_ERROR_DOM_MEDIA_DEMUXER_ERR,
                   RESULT_DETAIL("No MP4 audio or video tracks")),
       __func__);
   }
 
   if (audioTrackCount != 0) {
-    mAudioDemuxers.SetLength(audioTrackCount);
     for (size_t i = 0; i < audioTrackCount; i++) {
       UniquePtr<TrackInfo> info =
         metadata.GetTrackInfo(TrackInfo::kAudioTrack, i);
       if (info) {
         FallibleTArray<mp4_demuxer::Index::Indice> indices;
         if (metadata.ReadTrackIndex(indices, info->mTrackId)) {
-          mAudioDemuxers[i] = new MP4TrackDemuxer(this, Move(info), indices);
+          mAudioDemuxers.AppendElement(
+            new MP4TrackDemuxer(this, Move(info), indices));
         }
       }
     }
   }
 
   if (videoTrackCount != 0) {
-    mVideoDemuxers.SetLength(videoTrackCount);
     for (size_t i = 0; i < videoTrackCount; i++) {
       UniquePtr<TrackInfo> info =
         metadata.GetTrackInfo(TrackInfo::kVideoTrack, i);
       if (info) {
         FallibleTArray<mp4_demuxer::Index::Indice> indices;
         if (metadata.ReadTrackIndex(indices, info->mTrackId)) {
-          mVideoDemuxers[i] = new MP4TrackDemuxer(this, Move(info), indices);
+          mVideoDemuxers.AppendElement(
+            new MP4TrackDemuxer(this, Move(info), indices));
         }
       }
     }
   }
 
   const mp4_demuxer::CryptoFile& cryptoFile = metadata.Crypto();
   if (cryptoFile.valid) {
     const nsTArray<mp4_demuxer::PsshInfo>& psshs = cryptoFile.pssh;