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

Commit b9a69e22 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Fix MonoPipe ownership in StreamRemoteSubmix

MonoPipeReader does not hold a strong reference to MonoPipe.
Thus the client code needs to ensure that their lifetimes
are synchronized. In StreamRemoteSubmix::inRead the code
holds a strong pointer to a MonoPipeReader but not to the
MonoPipe which makes it possible for MonoPipe to be released
from another thread and causing the read operation to crash.

Bug: 377325461
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I400aa91204a3464dcb8fca723c8c87005fb6502f
parent bcf8e249
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -283,6 +283,15 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
        }
        return ::android::OK;
    }
    // get and hold the sink because 'MonoPipeReader' does not hold a strong pointer to it.
    sp<MonoPipe> sink = mCurrentRoute->getSink();
    if (sink == nullptr) {
        if (++mReadErrorCount < kMaxErrorLogs) {
            LOG(ERROR) << __func__
                       << ": the sink has been released! (not all errors will be logged)";
        }
        return ::android::OK;
    }
    mReadErrorCount = 0;

    LOG(VERBOSE) << __func__ << ": " << mDeviceAddress.toString() << ", " << frameCount