audio policy: fix overflow in condition wait timeout
Do not pass a large value to Condition::waitRelative() as this
can cause an overflow in pthread_cond_timedwait_relative_np() when
converting to absolute time.
Bug: 26891803
Change-Id: Ie2a00bca52d469aa08b2718089dc19cfb1f3475f
diff --git a/services/audiopolicy/service/AudioPolicyService.cpp b/services/audiopolicy/service/AudioPolicyService.cpp
index 0c5d275..363968c 100644
--- a/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/services/audiopolicy/service/AudioPolicyService.cpp
@@ -449,7 +449,7 @@
bool AudioPolicyService::AudioCommandThread::threadLoop()
{
- nsecs_t waitTime = INT64_MAX;
+ nsecs_t waitTime = -1;
mLock.lock();
while (!exitPending())
@@ -614,7 +614,7 @@
command->mCond.signal();
}
}
- waitTime = INT64_MAX;
+ waitTime = -1;
// release mLock before releasing strong reference on the service as
// AudioPolicyService destructor calls AudioCommandThread::exit() which
// acquires mLock.
@@ -636,7 +636,11 @@
// has a finite delay. So unless we are exiting it is safe to wait.
if (!exitPending()) {
ALOGV("AudioCommandThread() going to sleep");
- mWaitWorkCV.waitRelative(mLock, waitTime);
+ if (waitTime == -1) {
+ mWaitWorkCV.wait(mLock);
+ } else {
+ mWaitWorkCV.waitRelative(mLock, waitTime);
+ }
}
}
// release delayed commands wake lock before quitting