From 4f6c54ecb384398f33a48c1f1a2879fe44127ead Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 14 Aug 2020 14:36:30 +0200 Subject: [PATCH] output/osx: catch kAudioDevicePropertyHogMode errors Our AudioObjectGetPropertyDataT() wrapper throws exception on error, and calling it from OSXOutput::Disable() can cause MPD crash due to std::terminate(). Closes https://github.com/MusicPlayerDaemon/MPD/issues/932 --- NEWS | 1 + src/output/plugins/OSXOutputPlugin.cxx | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index b698d4f5f..e23b1d0e5 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ ver 0.21.26 (not yet released) * output + - osx: fix crash bug - sles: support floating point samples ver 0.21.25 (2020/07/06) diff --git a/src/output/plugins/OSXOutputPlugin.cxx b/src/output/plugins/OSXOutputPlugin.cxx index 0a51af7a5..f4a843119 100644 --- a/src/output/plugins/OSXOutputPlugin.cxx +++ b/src/output/plugins/OSXOutputPlugin.cxx @@ -477,7 +477,7 @@ osx_output_set_buffer_size(AudioUnit au, AudioStreamBasicDescription desc) } static void -osx_output_hog_device(AudioDeviceID dev_id, bool hog) +osx_output_hog_device(AudioDeviceID dev_id, bool hog) noexcept { static constexpr AudioObjectPropertyAddress aopa = { kAudioDevicePropertyHogMode, @@ -485,8 +485,16 @@ osx_output_hog_device(AudioDeviceID dev_id, bool hog) kAudioObjectPropertyElementMaster }; - pid_t hog_pid = AudioObjectGetPropertyDataT(dev_id, - aopa); + pid_t hog_pid; + + try { + hog_pid = AudioObjectGetPropertyDataT(dev_id, aopa); + } catch (...) { + Log(LogLevel::DEBUG, std::current_exception(), + "Failed to query HogMode"); + return; + } + if (hog) { if (hog_pid != -1) { FormatDebug(osx_output_domain,