From 05e6d423d9211d940a247ae23c99198985f20cb3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 20 Apr 2017 07:33:13 +0200 Subject: ao_wasapi_changenotify: fix potential race condition IMMDeviceEnumerator_RegisterEndpointNotificationCallback() will start listening for notifications, and is the point at which callbacks can start firing. These callbacks will read the fields we set after the register calls, which is a potential race condition. Move it upwards. --- audio/out/ao_wasapi_changenotify.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/audio/out/ao_wasapi_changenotify.c b/audio/out/ao_wasapi_changenotify.c index b9806e0adb..dc529b638d 100644 --- a/audio/out/ao_wasapi_changenotify.c +++ b/audio/out/ao_wasapi_changenotify.c @@ -202,14 +202,6 @@ HRESULT wasapi_change_init(struct ao *ao, bool is_hotplug) (void **)&change->pEnumerator); EXIT_ON_ERROR(hr); - // COM voodoo to emulate c++ class - change->client.lpVtbl = &sIMMNotificationClientVtbl; - - // register the change notification client - hr = IMMDeviceEnumerator_RegisterEndpointNotificationCallback( - change->pEnumerator, (IMMNotificationClient *)change); - EXIT_ON_ERROR(hr); - // so the callbacks can access the ao change->ao = ao; @@ -224,6 +216,14 @@ HRESULT wasapi_change_init(struct ao *ao, bool is_hotplug) MP_VERBOSE(ao, "Monitoring changes in device %S\n", change->monitored); } + // COM voodoo to emulate c++ class + change->client.lpVtbl = &sIMMNotificationClientVtbl; + + // register the change notification client + hr = IMMDeviceEnumerator_RegisterEndpointNotificationCallback( + change->pEnumerator, (IMMNotificationClient *)change); + EXIT_ON_ERROR(hr); + return hr; exit_label: MP_ERR(state, "Error setting up device change monitoring: %s\n", -- cgit v1.2.3