Skip to content

Commit 8b7a088

Browse files
committed
Call IOHIDDeviceClose() if needed in hid_close() on macOS
Unregistering the input report callback marks the device as disconnected, so IOHIDDeviceClose() would never be called if the device wasn't already disconnected when hid_close() was called. Fixes #12255 (cherry picked from commit 2442c85)
1 parent 7fc5eda commit 8b7a088

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/hidapi/mac/hid.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,11 +1135,14 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
11351135

11361136
void HID_API_EXPORT hid_close(hid_device *dev)
11371137
{
1138+
int disconnected;
1139+
11381140
if (!dev)
11391141
return;
11401142

11411143
/* Disconnect the report callback before close. */
1142-
if (!dev->disconnected) {
1144+
disconnected = dev->disconnected;
1145+
if (!disconnected) {
11431146
IOHIDDeviceRegisterInputReportCallback(
11441147
dev->device_handle, dev->input_report_buf, dev->max_input_report_len,
11451148
NULL, dev);
@@ -1163,7 +1166,7 @@ void HID_API_EXPORT hid_close(hid_device *dev)
11631166
/* Close the OS handle to the device, but only if it's not
11641167
been unplugged. If it's been unplugged, then calling
11651168
IOHIDDeviceClose() will crash. */
1166-
if (!dev->disconnected) {
1169+
if (!disconnected) {
11671170
IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone);
11681171
}
11691172

0 commit comments

Comments
 (0)