audio policy: fix inifinite loop in clearAudioPatches()
releaseAudioPatch() does not necessarily remove the audio patch
from the list.
Scan the list from the top down to avoid adjusting the index.
Bug: 18621514.
Change-Id: I58787154680f7cb1818509017835b1693d62190f
diff --git a/services/audiopolicy/AudioPolicyManager.cpp b/services/audiopolicy/AudioPolicyManager.cpp
index b5a3d5b..76acc41 100644
--- a/services/audiopolicy/AudioPolicyManager.cpp
+++ b/services/audiopolicy/AudioPolicyManager.cpp
@@ -2650,13 +2650,10 @@
void AudioPolicyManager::clearAudioPatches(uid_t uid)
{
- for (ssize_t i = 0; i < (ssize_t)mAudioPatches.size(); i++) {
+ for (ssize_t i = (ssize_t)mAudioPatches.size() - 1; i >= 0; i--) {
sp<AudioPatch> patchDesc = mAudioPatches.valueAt(i);
if (patchDesc->mUid == uid) {
- // releaseAudioPatch() removes the patch from mAudioPatches
- if (releaseAudioPatch(mAudioPatches.keyAt(i), uid) == NO_ERROR) {
- i--;
- }
+ releaseAudioPatch(mAudioPatches.keyAt(i), uid);
}
}
}