AudioFlinger: Fix deadlock when createEffect_l fails.
The handle.clear() will cause deadlock if init of EffectHandle
failed due to NO_MEMORY in createEffect_l.
Test: Monkey test, Instrumented test.
Bug: 75031792
Change-Id: Ie0f38d76a66aeafe26903dda6690d1fe7fca4464
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 8033382..ea06b6c 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -3139,16 +3139,21 @@
bool pinned = (sessionId > AUDIO_SESSION_OUTPUT_MIX) && isSessionAcquired_l(sessionId);
handle = thread->createEffect_l(client, effectClient, priority, sessionId,
&desc, enabled, &lStatus, pinned);
- if (handle != 0 && id != NULL) {
- *id = handle->id();
- }
- if (handle == 0) {
+ if (lStatus != NO_ERROR && lStatus != ALREADY_EXISTS) {
// remove local strong reference to Client with mClientLock held
Mutex::Autolock _cl(mClientLock);
client.clear();
+ } else {
+ // handle must be valid here, but check again to be safe.
+ if (handle.get() != nullptr && id != nullptr) *id = handle->id();
}
}
+ if (lStatus != NO_ERROR && lStatus != ALREADY_EXISTS) {
+ // handle must be cleared outside lock.
+ handle.clear();
+ }
+
Exit:
*status = lStatus;
return handle;