mirror of https://github.com/mpv-player/mpv
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:
parent
5ae25ae424
commit
05e6d423d9
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue