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

Commit c6ef7dce authored by Wonsik Kim's avatar Wonsik Kim Committed by Jessica Wagantall
Browse files

DO NOT MERGE NuCachedSource2: fix possible erroneous early free

Because the constructor of NuCachedSource2 sent a message to
AHandlerReflector object, AHandlerReflector::onMessageReceived could
have executed just before the object gets wrapped in a strong
pointer, resulting in erroneous early free. Fix the issue by using
static Create function to ensure the message is sent after the
object is wrapped in a sp.

Ticket: CYNGNOS-1299
Bug: 23882800

Change-Id: I38a9d7a3083f184b4c81d0b00ba1661721278855
(cherry picked from commit 0d35dd20)
parent 3162a5fb
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -2900,11 +2900,11 @@ status_t AwesomePlayer::finishSetDataSource_l() {
            // The widevine extractor does its own caching.
            // The widevine extractor does its own caching.


#if 0
#if 0
            mCachedSource = new NuCachedSource2(
            mCachedSource = NuCachedSource2::Create(
                    new ThrottledSource(
                    new ThrottledSource(
                        mConnectingDataSource, 50 * 1024 /* bytes/sec */));
                        mConnectingDataSource, 50 * 1024 /* bytes/sec */));
#else
#else
            mCachedSource = new NuCachedSource2(
            mCachedSource = NuCachedSource2::Create(
                    mConnectingDataSource,
                    mConnectingDataSource,
                    cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
                    cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
                    disconnectAtHighwatermark);
                    disconnectAtHighwatermark);
+1 −1
Original line number Original line Diff line number Diff line
@@ -318,7 +318,7 @@ sp<DataSource> DataSource::CreateFromURI(
                *contentType = httpSource->getMIMEType();
                *contentType = httpSource->getMIMEType();
            }
            }


            source = new NuCachedSource2(
            source = NuCachedSource2::Create(
                    httpSource,
                    httpSource,
                    cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
                    cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
                    disconnectAtHighwatermark);
                    disconnectAtHighwatermark);
+12 −3
Original line number Original line Diff line number Diff line
@@ -225,9 +225,6 @@ NuCachedSource2::NuCachedSource2(
    // So whenever we call DataSource::readAt it may end up in a call to
    // So whenever we call DataSource::readAt it may end up in a call to
    // IMediaHTTPConnection::readAt and therefore call back into JAVA.
    // IMediaHTTPConnection::readAt and therefore call back into JAVA.
    mLooper->start(false /* runOnCallingThread */, true /* canCallJava */);
    mLooper->start(false /* runOnCallingThread */, true /* canCallJava */);

    Mutex::Autolock autoLock(mLock);
    (new AMessage(kWhatFetchMore, mReflector->id()))->post();
}
}


NuCachedSource2::~NuCachedSource2() {
NuCachedSource2::~NuCachedSource2() {
@@ -238,6 +235,18 @@ NuCachedSource2::~NuCachedSource2() {
    mCache = NULL;
    mCache = NULL;
}
}


// static
sp<NuCachedSource2> NuCachedSource2::Create(
        const sp<DataSource> &source,
        const char *cacheConfig,
        bool disconnectAtHighwatermark) {
    sp<NuCachedSource2> instance = new NuCachedSource2(
            source, cacheConfig, disconnectAtHighwatermark);
    Mutex::Autolock autoLock(instance->mLock);
    (new AMessage(kWhatFetchMore, instance->mReflector->id()))->post();
    return instance;
}

status_t NuCachedSource2::getEstimatedBandwidthKbps(int32_t *kbps) {
status_t NuCachedSource2::getEstimatedBandwidthKbps(int32_t *kbps) {
    if (mSource->flags() & kIsHTTPBasedSource) {
    if (mSource->flags() & kIsHTTPBasedSource) {
        HTTPBase* source = static_cast<HTTPBase *>(mSource.get());
        HTTPBase* source = static_cast<HTTPBase *>(mSource.get());
+6 −1
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@ struct ALooper;
struct PageCache;
struct PageCache;


struct NuCachedSource2 : public DataSource {
struct NuCachedSource2 : public DataSource {
    NuCachedSource2(
    static sp<NuCachedSource2> Create(
            const sp<DataSource> &source,
            const sp<DataSource> &source,
            const char *cacheConfig = NULL,
            const char *cacheConfig = NULL,
            bool disconnectAtHighwatermark = false);
            bool disconnectAtHighwatermark = false);
@@ -75,6 +75,11 @@ protected:
private:
private:
    friend struct AHandlerReflector<NuCachedSource2>;
    friend struct AHandlerReflector<NuCachedSource2>;


    NuCachedSource2(
            const sp<DataSource> &source,
            const char *cacheConfig,
            bool disconnectAtHighwatermark);

    enum {
    enum {
        kPageSize                       = 65536,
        kPageSize                       = 65536,
        kDefaultHighWaterThreshold      = 20 * 1024 * 1024,
        kDefaultHighWaterThreshold      = 20 * 1024 * 1024,