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

Commit 116df6ab authored by zhenjun.zhang's avatar zhenjun.zhang Committed by Andy Hung
Browse files

Fix mediaserver crash issue

mDeviceCallback is not guarded by a lock, so it may be
cleared twice when another thread calls removeAudioDeviceCallback.

Solution: Guard mDeviceCallback with a lock.

Test: monkey test
Bug: 209707170
Change-Id: I1ff93d058b8f8ff7addb2eb1cd86a1c03ba80777
parent fe5ce1bd
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -210,11 +210,13 @@ void AudioRecord::stopAndJoinCallbacks() {
        mAudioRecordThread->requestExitAndWait();
        mAudioRecordThread.clear();
    }
    // No lock here: worst case we remove a NULL callback which will be a nop

    AutoMutex lock(mLock);
    if (mDeviceCallback != 0 && mInput != AUDIO_IO_HANDLE_NONE) {
        // This may not stop all of these device callbacks!
        // TODO: Add some sort of protection.
        AudioSystem::removeAudioDeviceCallback(this, mInput, mPortId);
        mDeviceCallback.clear();
    }
}
status_t AudioRecord::set(
+2 −1
Original line number Diff line number Diff line
@@ -357,7 +357,8 @@ void AudioTrack::stopAndJoinCallbacks() {
        mAudioTrackThread->requestExitAndWait();
        mAudioTrackThread.clear();
    }
    // No lock here: worst case we remove a NULL callback which will be a nop

    AutoMutex lock(mLock);
    if (mDeviceCallback != 0 && mOutput != AUDIO_IO_HANDLE_NONE) {
        // This may not stop all of these device callbacks!
        // TODO: Add some sort of protection.