summaryrefslogtreecommitdiff
path: root/libs/gui/BufferQueueProducer.cpp
diff options
context:
space:
mode:
author Mathias Agopian <mathias@google.com> 2017-06-06 17:40:00 +0000
committer android-build-merger <android-build-merger@google.com> 2017-06-06 17:40:00 +0000
commitee464e00d3db7b16eb6b75932665f8ccc732d013 (patch)
treeb8ae6bd7dae77afccf1a56d05788198bcda0046d /libs/gui/BufferQueueProducer.cpp
parent2d4959d8ebb865f67a6568ac76e16492797f1611 (diff)
parent46361c6c2b649f44f380222810378957ecb6fcc1 (diff)
fix race condition that can cause a use after free am: 59485525a6 am: 5da64c91d0
am: 46361c6c2b Change-Id: I33758163baac3c96525751d313091a5bce0d5377
Diffstat (limited to 'libs/gui/BufferQueueProducer.cpp')
-rw-r--r--libs/gui/BufferQueueProducer.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index b2169c84c7..ff85eb5ce8 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -921,7 +921,11 @@ status_t BufferQueueProducer::queueBuffer(int slot,
// Call back without the main BufferQueue lock held, but with the callback
// lock held so we can ensure that callbacks occur in order
- {
+
+ int connectedApi;
+ sp<Fence> lastQueuedFence;
+
+ { // scope for the lock
Mutex::Autolock lock(mCallbackMutex);
while (callbackTicket != mCurrentCallbackTicket) {
mCallbackCondition.wait(mCallbackMutex);
@@ -933,20 +937,24 @@ status_t BufferQueueProducer::queueBuffer(int slot,
frameReplacedListener->onFrameReplaced(item);
}
+ connectedApi = mCore->mConnectedApi;
+ lastQueuedFence = std::move(mLastQueueBufferFence);
+
+ mLastQueueBufferFence = std::move(fence);
+ mLastQueuedCrop = item.mCrop;
+ mLastQueuedTransform = item.mTransform;
+
++mCurrentCallbackTicket;
mCallbackCondition.broadcast();
}
// Wait without lock held
- if (mCore->mConnectedApi == NATIVE_WINDOW_API_EGL) {
+ if (connectedApi == NATIVE_WINDOW_API_EGL) {
// Waiting here allows for two full buffers to be queued but not a
// third. In the event that frames take varying time, this makes a
// small trade-off in favor of latency rather than throughput.
- mLastQueueBufferFence->waitForever("Throttling EGL Production");
+ lastQueuedFence->waitForever("Throttling EGL Production");
}
- mLastQueueBufferFence = fence;
- mLastQueuedCrop = item.mCrop;
- mLastQueuedTransform = item.mTransform;
return NO_ERROR;
}