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

Commit 9b2a7f24 authored by Wonsik Kim's avatar Wonsik Kim Committed by Michael Bestas
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.

Bug: 23882800
Change-Id: I38a9d7a3083f184b4c81d0b00ba1661721278855
(cherry picked from commit c894f81b)
parent 5873008e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2862,11 +2862,11 @@ status_t AwesomePlayer::finishSetDataSource_l() {
            // The widevine extractor does its own caching.

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

            source = new NuCachedSource2(
            source = NuCachedSource2::Create(
                    httpSource,
                    cacheConfig.isEmpty() ? NULL : cacheConfig.string());
        } else {
+12 −3
Original line number Diff line number Diff line
@@ -217,9 +217,6 @@ NuCachedSource2::NuCachedSource2(
    mLooper->setName("NuCachedSource2");
    mLooper->registerHandler(mReflector);
    mLooper->start();

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

NuCachedSource2::~NuCachedSource2() {
@@ -230,6 +227,18 @@ NuCachedSource2::~NuCachedSource2() {
    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;
}

void NuCachedSource2::enableNonBlockingRead(bool flag) {
    mIsNonBlockingMode = flag;
}
+6 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ struct ALooper;
struct PageCache;

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

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

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