Rémi Bernon : dinput: Wait for CancelIoEx completion when unacquiring HID joysticks.

Alexandre Julliard julliard at winehq.org
Fri Oct 8 14:12:27 CDT 2021


Module: wine
Branch: master
Commit: bbb68aeaae5476257eec7b41da8c854a05b7b696
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bbb68aeaae5476257eec7b41da8c854a05b7b696

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Fri Oct  8 15:36:01 2021 +0200

dinput: Wait for CancelIoEx completion when unacquiring HID joysticks.

Otherwise we may later write the cancelled status to invalid memory.

Also use a manual-reset event, as it should be for overlapped I/O, so
all waiters are woken up on cancel.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/joystick_hid.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index 6f9e9987e6e..a0ea1a7bf1c 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -599,7 +599,6 @@ static ULONG hid_joystick_private_decref( struct hid_joystick *impl )
         HeapFree( GetProcessHeap(), 0, tmp.input_report_buf );
         HeapFree( GetProcessHeap(), 0, tmp.input_extra_caps );
         HidD_FreePreparsedData( tmp.preparsed );
-        CancelIoEx( tmp.device, &tmp.read_ovl );
         CloseHandle( tmp.base.read_event );
         CloseHandle( tmp.device );
     }
@@ -981,7 +980,7 @@ static HRESULT WINAPI hid_joystick_Unacquire( IDirectInputDevice8W *iface )
     {
         ret = CancelIoEx( impl->device, &impl->read_ovl );
         if (!ret) WARN( "CancelIoEx failed, last error %u\n", GetLastError() );
-
+        else WaitForSingleObject( impl->base.read_event, INFINITE );
         IDirectInputDevice8_SendForceFeedbackCommand( iface, DISFFC_RESET );
         impl->base.acquired = FALSE;
     }
@@ -2244,7 +2243,7 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID
     if (FAILED(hr)) return hr;
     impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": hid_joystick.base.crit");
     impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
-    impl->base.read_event = CreateEventA( NULL, FALSE, FALSE, NULL );
+    impl->base.read_event = CreateEventW( NULL, TRUE, FALSE, NULL );
     impl->base.read_callback = hid_joystick_read_state;
 
     hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed,




More information about the wine-cvs mailing list