libgui: fix a race in CpuConsumer::lockNextBuffer
mCurrentLockedBuffers must be accessed with the mutex. Constify
mMaxLockedBuffers as well for clarity.
Test: libgui_test
Change-Id: I7c40d135bcf2aa6a90ecff74d6d8107fc530e815
diff --git a/libs/gui/CpuConsumer.cpp b/libs/gui/CpuConsumer.cpp
index f909e3b..e5e02b4 100644
--- a/libs/gui/CpuConsumer.cpp
+++ b/libs/gui/CpuConsumer.cpp
@@ -168,6 +168,9 @@
status_t err;
if (!nativeBuffer) return BAD_VALUE;
+
+ Mutex::Autolock _l(mMutex);
+
if (mCurrentLockedBuffers == mMaxLockedBuffers) {
CC_LOGW("Max buffers have been locked (%zd), cannot lock anymore.",
mMaxLockedBuffers);
@@ -175,9 +178,6 @@
}
BufferItem b;
-
- Mutex::Autolock _l(mMutex);
-
err = acquireBufferLocked(&b, 0);
if (err != OK) {
if (err == BufferQueue::NO_BUFFER_AVAILABLE) {