RecordThread: Fix sp<> release with mutex held
The RecordThread activeTrack is now released at the end of each
read processing loop cycle, when the ThreadBase_Mutex is not held.
Prior to this, the activeTrack was being released when the new
activeTrack was determined (under lock). Occasionally
when the activeTrack changed and the prior cycle's activeTrack held
the last refCount, the RecordTrack dtor was called while the
ThreadBase_Mutex was held, resulting in a lock
order inversion when the TrackBase's client sp<> is released.
Test: compiles
Bug: 329604636
Merged-In: Ib971dd48098207d2bbc78670bfcf8e14e70efb3f
Change-Id: Ib971dd48098207d2bbc78670bfcf8e14e70efb3f
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index bba3d86..1d7c356 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -8153,7 +8153,6 @@
inputStandBy();
reacquire_wakelock:
- sp<IAfRecordTrack> activeTrack;
{
audio_utils::lock_guard _l(mutex());
acquireWakeLock_l();
@@ -8169,6 +8168,8 @@
// loop while there is work to do
for (int64_t loopCount = 0;; ++loopCount) { // loopCount used for statistics tracking
+ // Note: these sp<> are released at the end of the for loop outside of the mutex() lock.
+ sp<IAfRecordTrack> activeTrack;
Vector<sp<IAfEffectChain>> effectChains;
// activeTracks accumulates a copy of a subset of mActiveTracks