From 942481eee58cb1e81853bc79e25359a7ee8a59e1 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Thu, 16 Oct 2014 10:51:23 -0700 Subject: Fix freed memory references 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 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'media') diff --git a/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/MPEG4Extractor.cpp index 1729f93..d922dc0 100644 --- a/media/libstagefright/MPEG4Extractor.cpp +++ b/media/libstagefright/MPEG4Extractor.cpp @@ -48,7 +48,8 @@ namespace android { class MPEG4Source : public MediaSource { public: // Caller retains ownership of both "dataSource" and "sampleTable". - MPEG4Source(const sp &format, + MPEG4Source(const sp &owner, + const sp &format, const sp &dataSource, int32_t timeScale, const sp &sampleTable, @@ -70,6 +71,8 @@ protected: private: Mutex mLock; + // keep the MPEG4Extractor around, since we're referencing its data + sp mOwner; sp mFormat; sp mDataSource; int32_t mTimescale; @@ -2593,7 +2596,7 @@ sp 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 &owner, const sp &format, const sp &dataSource, int32_t timeScale, @@ -2947,7 +2951,8 @@ MPEG4Source::MPEG4Source( Vector &sidx, const Trex *trex, off64_t firstMoofOffset) - : mFormat(format), + : mOwner(owner), + mFormat(format), mDataSource(dataSource), mTimescale(timeScale), mSampleTable(sampleTable), -- cgit v1.1