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

Commit c65e8644 authored by chaviw's avatar chaviw Committed by Chavi Weingarten
Browse files

Remove promoting weak pointer off main thread.

If a Layer weak pointer is promoted on a thread other than the main
thread, it risks calling the destructor off the main thread. This causes
a lot of issues since there is no lock held in the Layer destructor. The
destructor expects to only ever get called on the main thread

The change here stores a raw pointer instead of a weak pointer. This
should be safe since BufferLayerConsumer lifecycle follows the Layer
lifecycle so the raw Layer pointer will never be invalid.

Test: Not easy to reproduce but no issues with this change
Fixes: 150879387
Change-Id: I51fbc2ca5052c5dbf8e875b557a034d40e4a0b39
parent 2c728339
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -443,10 +443,7 @@ void BufferLayerConsumer::freeBufferLocked(int slotIndex) {
}

void BufferLayerConsumer::onDisconnect() {
    sp<Layer> l = mLayer.promote();
    if (l.get()) {
        l->onDisconnect();
    }
    mLayer->onDisconnect();
}

void BufferLayerConsumer::onSidebandStreamChanged() {
@@ -480,10 +477,7 @@ void BufferLayerConsumer::onBufferAvailable(const BufferItem& item) {

void BufferLayerConsumer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
                                                   FrameEventHistoryDelta* outDelta) {
    sp<Layer> l = mLayer.promote();
    if (l.get()) {
        l->addAndGetFrameTimestamps(newTimestamps, outDelta);
    }
    mLayer->addAndGetFrameTimestamps(newTimestamps, outDelta);
}

void BufferLayerConsumer::abandonLocked() {
+1 −1
Original line number Diff line number Diff line
@@ -332,7 +332,7 @@ private:
    const uint32_t mTexName;

    // The layer for this BufferLayerConsumer
    const wp<Layer> mLayer;
    Layer* mLayer;

    wp<ContentsChangedListener> mContentsChangedListener;