[APU] fix potential semaphore leak on invalid client index

This commit is contained in:
Herman S.
2025-10-17 00:18:20 +09:00
parent c28019e333
commit 7887efa69f

View File

@@ -248,6 +248,14 @@ void AudioSystem::SubmitFrame(size_t index, float* samples) {
"(in_use={}, driver={:p})",
index, index < kMaximumClientCount ? clients_[index].in_use : false,
index < kMaximumClientCount ? (void*)clients_[index].driver : nullptr);
// Submit silence instead of dropping the frame to maintain the callback
// chain. If we don't submit anything, the audio driver's OnBufferEnd
// callback will never fire, causing the semaphore to leak.
if (index < kMaximumClientCount && clients_[index].driver) {
static float silence[apu::AudioDriver::kFrameSamplesMax] = {0};
(clients_[index].driver)->SubmitFrame(silence);
}
return;
}
(clients_[index].driver)->SubmitFrame(samples);