Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 942481ee authored by Marco Nelissen's avatar Marco Nelissen
Browse files

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
parent 380757ba
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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),