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

Commit 2901dd5a authored by Linus Nilsson's avatar Linus Nilsson Committed by Android (Google) Code Review
Browse files

Merge "Transcoder: Fix crash in PassthroughTrackTranscoder"

parents 36cd068a 16a5521e
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -44,23 +44,24 @@ uint8_t* PassthroughTrackTranscoder::BufferPool::getBufferWithSize(size_t minimu
    // Check if the free list contains a large enough buffer.
    auto it = mFreeBufferMap.lower_bound(minimumBufferSize);
    if (it != mFreeBufferMap.end()) {
        uint8_t* buffer = it->second;
        mFreeBufferMap.erase(it);
        return it->second;
    }

    // Allocate a new buffer.
    uint8_t* buffer = new (std::nothrow) uint8_t[minimumBufferSize];
    if (buffer == nullptr) {
        LOG(ERROR) << "Unable to allocate new buffer of size: " << minimumBufferSize;
        return nullptr;
        return buffer;
    }

    // If the maximum buffer count is reached, remove an existing free buffer.
    if (mAddressSizeMap.size() >= mMaxBufferCount) {
        auto it = mFreeBufferMap.begin();
        mFreeBufferMap.erase(it);
        mAddressSizeMap.erase(it->second);
        delete[] it->second;
        mFreeBufferMap.erase(it);
    }

    // Allocate a new buffer.
    uint8_t* buffer = new (std::nothrow) uint8_t[minimumBufferSize];
    if (buffer == nullptr) {
        LOG(ERROR) << "Unable to allocate new buffer of size: " << minimumBufferSize;
        return nullptr;
    }

    // Add the buffer to the tracking set.