diff --git a/services/surfaceflinger/BufferLayerConsumer.cpp b/services/surfaceflinger/BufferLayerConsumer.cpp index 648d129a5f..8722952bba 100644 --- a/services/surfaceflinger/BufferLayerConsumer.cpp +++ b/services/surfaceflinger/BufferLayerConsumer.cpp @@ -452,6 +452,13 @@ void BufferLayerConsumer::freeBufferLocked(int slotIndex) { } void BufferLayerConsumer::onDisconnect() { + Mutex::Autolock lock(mMutex); + + if (mAbandoned) { + // Nothing to do if we're already abandoned. + return; + } + mLayer->onDisconnect(); } @@ -486,6 +493,13 @@ void BufferLayerConsumer::onBufferAvailable(const BufferItem& item) { void BufferLayerConsumer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, FrameEventHistoryDelta* outDelta) { + Mutex::Autolock lock(mMutex); + + if (mAbandoned) { + // Nothing to do if we're already abandoned. + return; + } + mLayer->addAndGetFrameTimestamps(newTimestamps, outDelta); } diff --git a/services/surfaceflinger/BufferLayerConsumer.h b/services/surfaceflinger/BufferLayerConsumer.h index c71a1d9f7a..5e3044fd98 100644 --- a/services/surfaceflinger/BufferLayerConsumer.h +++ b/services/surfaceflinger/BufferLayerConsumer.h @@ -331,8 +331,8 @@ private: // construction time. const uint32_t mTexName; - // The layer for this BufferLayerConsumer - Layer* mLayer; + // The layer for this BufferLayerConsumer. Always check mAbandoned before accessing. + Layer* mLayer GUARDED_BY(mMutex); wp mContentsChangedListener;