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

Commit 4ed04ff8 authored by Pramodh Kumar Mukunda's avatar Pramodh Kumar Mukunda Committed by Zhao Wei Liew
Browse files

gralloc1: Acquire mutex early in release

Due to race condition between release and retain calls, retain return stale handle.
Which results in crash in SurfaceFlinger
Fix crash by acquiring mutex early in release function

Bug: 32384569
Change-Id: I4b763bbcacd9905492d19fafc9b91e4c7e1cc53e
(cherry picked from commit 6a711d2b)
parent 29fa32db
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -313,6 +313,7 @@ gralloc1_error_t Gralloc1On0Adapter::getphys(
gralloc1_error_t Gralloc1On0Adapter::retain(
        const std::shared_ptr<Buffer>& buffer)
{
    std::lock_guard<std::mutex> lock(mBufferMutex);
    buffer->retain();
    return GRALLOC1_ERROR_NONE;
}
@@ -320,6 +321,7 @@ gralloc1_error_t Gralloc1On0Adapter::retain(
gralloc1_error_t Gralloc1On0Adapter::release(
        const std::shared_ptr<Buffer>& buffer)
{
    std::lock_guard<std::mutex> lock(mBufferMutex);
    if (!buffer->release()) {
        return GRALLOC1_ERROR_NONE;
    }
@@ -339,7 +341,6 @@ gralloc1_error_t Gralloc1On0Adapter::release(
        }
    }

    std::lock_guard<std::mutex> lock(mBufferMutex);
    mBuffers.erase(handle);
    return GRALLOC1_ERROR_NONE;
}