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

Commit 5bb0fb50 authored by Pavan Chikkala's avatar Pavan Chikkala Committed by Ethan Chen
Browse files

audio: Fix for race conditions in direct audio track

-Issue: Mediaserver crash is observed in direct track functions.
-Rootcause: Between write and flush functions, write and destructor
effectpool buffers are accessed without any synchronization that
 might lead to operations on null buffers and cause crash.
-Fix: Use mEffectLock to synchronize access of effectpool buffers.

Change-Id: I5982e31fd6d292a9fe28dfee4cf75ebfe0ade5e6
CRs-Fixed: 515107
(cherry picked from commit b14c28f0d3b51ee989640aa46f3addcfabccb6be)
(cherry picked from commit 782f8512023facb1b655fb636bdcbd19af21b493)
(cherry picked from commit 1601287d6a06e11d782a821791bf1f5a9dcbd188)
parent 802e22b9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -6475,8 +6475,10 @@ ssize_t AudioFlinger::DirectAudioTrack::write(const void *buffer, size_t size) {

void AudioFlinger::DirectAudioTrack::flush() {
    if (mFlag & AUDIO_OUTPUT_FLAG_LPA) {
        mEffectLock.lock();
        mEffectsPool.clear();
        mEffectsPool = mBufPool;
        mEffectLock.unlock();
    }
    mOutputDesc->stream->flush(mOutputDesc->stream);
}
@@ -6557,6 +6559,7 @@ void AudioFlinger::DirectAudioTrack::deallocateBufPool() {

    //1. Deallocate the local memory
    //2. Remove all the buffers from bufpool
    mEffectLock.lock();
    while (!mBufPool.empty())  {
        List<BufferInfo>::iterator it = mBufPool.begin();
        BufferInfo &memBuffer = *it;
@@ -6568,6 +6571,8 @@ void AudioFlinger::DirectAudioTrack::deallocateBufPool() {
        ALOGV("Removing from bufpool");
        mBufPool.erase(it);
    }
    mEffectsPool.clear();
    mEffectLock.unlock();

    free(mEffectsThreadScratchBuffer);
    mEffectsThreadScratchBuffer = NULL;