From 9cbaedd2cde925a215447e7970e0f019e719d014 Mon Sep 17 00:00:00 2001 From: Chun-Min Chang Date: Tue, 9 Jul 2019 19:57:03 +0000 Subject: [PATCH] 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 --- media/libcubeb/cubeb-coreaudio-rs/README_MOZILLA | 2 +- media/libcubeb/cubeb-coreaudio-rs/src/backend/mod.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/media/libcubeb/cubeb-coreaudio-rs/README_MOZILLA b/media/libcubeb/cubeb-coreaudio-rs/README_MOZILLA index 6d6043db42ee..622b865853b7 100644 --- a/media/libcubeb/cubeb-coreaudio-rs/README_MOZILLA +++ b/media/libcubeb/cubeb-coreaudio-rs/README_MOZILLA @@ -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) diff --git a/media/libcubeb/cubeb-coreaudio-rs/src/backend/mod.rs b/media/libcubeb/cubeb-coreaudio-rs/src/backend/mod.rs index c74a19dedc07..e2afd37eca00 100644 --- a/media/libcubeb/cubeb-coreaudio-rs/src/backend/mod.rs +++ b/media/libcubeb/cubeb-coreaudio-rs/src/backend/mod.rs @@ -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(()) + } } }