Bug 1530715 - P23: Avoid poisoning the mutex for device_changed_callback. r=padenot

The mutex is considered poisoned whenever a thread panics while holding
the mutex. Registering a second device changed callback without unregistering
the original callback makes the thread panics while holding the mutex
for the device_changed_callback. This mutex will be used when device
property changed callback. If the mutex is poisoned then a device
property is changed, we will get another panic when firing the callback
because of using a poisoned mutex.

Differential Revision: https://phabricator.services.mozilla.com/D34056

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chun-Min Chang 2019-07-09 19:57:03 +00:00
Родитель b7048aa82e
Коммит 9cbaedd2cd
2 изменённых файлов: 7 добавлений и 4 удалений

Просмотреть файл

@ -3,4 +3,4 @@ git repository using the update.sh script.
The cubeb-coreaudio-rs git repository is: https://github.com/ChunMinChang/cubeb-coreaudio-rs
The git commit ID used was 3608c1dfc46466df5de8f03eca148f16a5dcd732 (2019-06-21 15:51:40 -0700)
The git commit ID used was 883d9919065abde325502a65ae265998ed046b91 (2019-06-21 15:51:40 -0700)

Просмотреть файл

@ -4371,9 +4371,12 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
let mut callback = self.device_changed_callback.lock().unwrap();
// Note: second register without unregister first causes 'nope' error.
// Current implementation requires unregister before register a new cb.
assert!(device_changed_callback.is_none() || callback.is_none());
*callback = device_changed_callback;
Ok(())
if device_changed_callback.is_some() && callback.is_some() {
Err(Error::invalid_parameter())
} else {
*callback = device_changed_callback;
Ok(())
}
}
}