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.
This commit is contained in:
wm4 2017-04-20 07:33:13 +02:00
parent 5ae25ae424
commit 05e6d423d9
1 changed files with 8 additions and 8 deletions

View File

@ -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",