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

Commit 6a711d2b authored by Pramodh Kumar Mukunda's avatar Pramodh Kumar Mukunda Committed by Arne Coucheron
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
parent 49b67afb
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -313,6 +313,7 @@ gralloc1_error_t Gralloc1On0Adapter::getphys(
gralloc1_error_t Gralloc1On0Adapter::retain(
gralloc1_error_t Gralloc1On0Adapter::retain(
        const std::shared_ptr<Buffer>& buffer)
        const std::shared_ptr<Buffer>& buffer)
{
{
    std::lock_guard<std::mutex> lock(mBufferMutex);
    buffer->retain();
    buffer->retain();
    return GRALLOC1_ERROR_NONE;
    return GRALLOC1_ERROR_NONE;
}
}
@@ -320,6 +321,7 @@ gralloc1_error_t Gralloc1On0Adapter::retain(
gralloc1_error_t Gralloc1On0Adapter::release(
gralloc1_error_t Gralloc1On0Adapter::release(
        const std::shared_ptr<Buffer>& buffer)
        const std::shared_ptr<Buffer>& buffer)
{
{
    std::lock_guard<std::mutex> lock(mBufferMutex);
    if (!buffer->release()) {
    if (!buffer->release()) {
        return GRALLOC1_ERROR_NONE;
        return GRALLOC1_ERROR_NONE;
    }
    }
@@ -339,7 +341,6 @@ gralloc1_error_t Gralloc1On0Adapter::release(
        }
        }
    }
    }


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