OSDN Git Service

Fix freed memory references
authorMarco Nelissen <marcone@google.com>
Thu, 16 Oct 2014 17:51:23 +0000 (10:51 -0700)
committerMarco Nelissen <marcone@google.com>
Thu, 16 Oct 2014 17:51:23 +0000 (10:51 -0700)
MPEG4Source references memory owned by MPEG4Extractor, and therefore an
MPEG4Extractor needs to be kept around as long as the MPEG4Sources obtained
from it exist.

Bug: 17890354
Change-Id: I399e18ec78517559ccc0914ffc7e099687c0ba51

media/libstagefright/MPEG4Extractor.cpp

index 1729f93..d922dc0 100644 (file)
@@ -48,7 +48,8 @@ namespace android {
 class MPEG4Source : public MediaSource {
 public:
     // Caller retains ownership of both "dataSource" and "sampleTable".
-    MPEG4Source(const sp<MetaData> &format,
+    MPEG4Source(const sp<MPEG4Extractor> &owner,
+                const sp<MetaData> &format,
                 const sp<DataSource> &dataSource,
                 int32_t timeScale,
                 const sp<SampleTable> &sampleTable,
@@ -70,6 +71,8 @@ protected:
 private:
     Mutex mLock;
 
+    // keep the MPEG4Extractor around, since we're referencing its data
+    sp<MPEG4Extractor> mOwner;
     sp<MetaData> mFormat;
     sp<DataSource> mDataSource;
     int32_t mTimescale;
@@ -2593,7 +2596,7 @@ sp<MediaSource> MPEG4Extractor::getTrack(size_t index) {
 
     ALOGV("getTrack called, pssh: %zu", mPssh.size());
 
-    return new MPEG4Source(
+    return new MPEG4Source(this,
             track->meta, mDataSource, track->timescale, track->sampleTable,
             mSidxEntries, trex, mMoofOffset);
 }
@@ -2940,6 +2943,7 @@ status_t MPEG4Extractor::updateAudioTrackInfoFromESDS_MPEG4Audio(
 ////////////////////////////////////////////////////////////////////////////////
 
 MPEG4Source::MPEG4Source(
+        const sp<MPEG4Extractor> &owner,
         const sp<MetaData> &format,
         const sp<DataSource> &dataSource,
         int32_t timeScale,
@@ -2947,7 +2951,8 @@ MPEG4Source::MPEG4Source(
         Vector<SidxEntry> &sidx,
         const Trex *trex,
         off64_t firstMoofOffset)
-    : mFormat(format),
+    : mOwner(owner),
+      mFormat(format),
       mDataSource(dataSource),
       mTimescale(timeScale),
       mSampleTable(sampleTable),