From 4be3cc597a67b0060ebdcf1c83e155df94af0cbc Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Fri, 30 Jul 2021 15:30:29 -0700 Subject: [PATCH 1/3] coreaudio: ensure we increment the tracking counter properly Signed-off-by: Steven Noonan --- miniaudio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 27425c72..7afcdf19 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -26525,8 +26525,8 @@ static ma_result ma_context__init_device_tracking__coreaudio(ma_context* pContex propAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice; ((ma_AudioObjectAddPropertyListener_proc)pContext->coreaudio.AudioObjectAddPropertyListener)(kAudioObjectSystemObject, &propAddress, &ma_default_device_changed__coreaudio, NULL); - g_DeviceTrackingInitCounter_CoreAudio += 1; } + g_DeviceTrackingInitCounter_CoreAudio += 1; } ma_spinlock_unlock(&g_DeviceTrackingInitLock_CoreAudio); From 43f2e28c200ea4daac151f4b79a656d82ac84bd1 Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Fri, 30 Jul 2021 15:32:36 -0700 Subject: [PATCH 2/3] coreaudio: don't allow g_DeviceTrackingInitCounter_CoreAudio to go negative Signed-off-by: Steven Noonan --- miniaudio.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 7afcdf19..3da43684 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -26539,7 +26539,8 @@ static ma_result ma_context__uninit_device_tracking__coreaudio(ma_context* pCont ma_spinlock_lock(&g_DeviceTrackingInitLock_CoreAudio); { - g_DeviceTrackingInitCounter_CoreAudio -= 1; + if (g_DeviceTrackingInitCounter_CoreAudio > 0) + g_DeviceTrackingInitCounter_CoreAudio -= 1; if (g_DeviceTrackingInitCounter_CoreAudio == 0) { AudioObjectPropertyAddress propAddress; From e358e72f674c4ade164aa21be74d2989fd454c93 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 31 Jul 2021 09:16:52 +1000 Subject: [PATCH 3/3] Core Audio: Fix a possible deadlock when uninitializing a device. --- miniaudio.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/miniaudio.h b/miniaudio.h index 3da43684..89173231 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -26556,6 +26556,8 @@ static ma_result ma_context__uninit_device_tracking__coreaudio(ma_context* pCont /* At this point there should be no tracked devices. If not there's an error somewhere. */ if (g_ppTrackedDevices_CoreAudio != NULL) { ma_context_post_error(pContext, NULL, MA_LOG_LEVEL_WARNING, "You have uninitialized all contexts while an associated device is still active.", MA_INVALID_OPERATION); + ma_spinlock_unlock(&g_DeviceTrackingInitLock_CoreAudio); + return MA_INVALID_OPERATION; } ma_mutex_uninit(&g_DeviceTrackingMutex_CoreAudio);