ruabmbua / hidapi-rs

Rust bindings for the hidapi C library
MIT License
173 stars 82 forks source link

Use CancelIoEx instead of CancelIo on windows_native #152

Closed YgorSouza closed 7 months ago

YgorSouza commented 7 months ago

Fixes a use-after-free bug when dropping the HidDevice from a thread other than the one that was last used to read it, because of a pending async operation that did not get canceled.

If the cancellation does not return an error, we get the overlapped result to block until it actually goes through. This is recommended by Microsoft in this example: https://learn.microsoft.com/en-us/windows/win32/fileio/canceling-pending-i-o-operations#canceling-asynchronous-io.

Closes #151

ruabmbua commented 7 months ago

Thanks for fixing this, will release a new version to crates.io.