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

Commit 0329492f authored by Pawin Vongmasa's avatar Pawin Vongmasa
Browse files

OMXNodeInstance: Guard mActiveBuffers by mLock

Test: atest CtsMediaTestCases

Bug: 135003556
Bug: 142777721
Change-Id: I02b5c0be94a674fe21884d9faa0c0c9cfbedd5fc
parent 9d730330
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@

#include <hidlmemory/mapping.h>

#include <vector>

static const OMX_U32 kPortIndexInput = 0;
static const OMX_U32 kPortIndexOutput = 1;

@@ -493,9 +495,7 @@ status_t OMXNodeInstance::freeNode() {

        case OMX_StateLoaded:
        {
            if (mActiveBuffers.size() > 0) {
            freeActiveBuffers();
            }
            FALLTHROUGH_INTENDED;
        }
        case OMX_StateInvalid:
@@ -2430,11 +2430,19 @@ void OMXNodeInstance::removeActiveBuffer(
}

void OMXNodeInstance::freeActiveBuffers() {
    // Make sure to count down here, as freeBuffer will in turn remove
    // the active buffer from the vector...
    for (size_t i = mActiveBuffers.size(); i > 0;) {
        i--;
        freeBuffer(mActiveBuffers[i].mPortIndex, mActiveBuffers[i].mID);
    std::vector<OMX_U32> portIndices;
    std::vector<IOMX::buffer_id> bufferIds;
    {
        // Access to mActiveBuffers must be protected by mLock.
        Mutex::Autolock _l(mLock);
        for (const ActiveBuffer& activeBuffer : mActiveBuffers) {
            portIndices.emplace_back(activeBuffer.mPortIndex);
            bufferIds.emplace_back(activeBuffer.mID);
        }
    }
    for (size_t i = bufferIds.size(); i > 0; ) {
        --i;
        freeBuffer(portIndices[i], bufferIds[i]);
    }
}