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

Commit 4199198a authored by Yin-Chia Yeh's avatar Yin-Chia Yeh
Browse files

NDK: fix undefined behavior

Fix a problem where we unlock a mutex after it's freed.
Also freeing a locked mutex can lead to undefined behavior

Test: run all camera2 NDK CTS tests
Change-Id: Ib56e9c4908e9bfdc06a936a6b7cfd90fbc948006
parent 68f1d284
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ AImage::AImage(AImageReader* reader, int32_t format, uint64_t usage, BufferItem*
        mTimestamp(timestamp), mWidth(width), mHeight(height), mNumPlanes(numPlanes) {
}

// Can only be called by free() with mLock hold
AImage::~AImage() {
    Mutex::Autolock _l(mLock);
    if (!mIsClosed) {
        LOG_ALWAYS_FATAL(
                "Error: AImage %p is deleted before returning buffer to AImageReader!", this);
@@ -78,7 +78,6 @@ AImage::free() {
        ALOGE("Cannot free AImage before close!");
        return;
    }
    Mutex::Autolock _l(mLock);
    delete this;
}