Skip to content

Commit 5b95114

Browse files
committed
Revert "Don't leak device handle in macOS 10.10 or newer"
This reverts commit 5925c27. Fixes #12807
1 parent 15fd3fc commit 5b95114

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

src/hidapi/configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ case $host in
7979
backend="mac"
8080
os="darwin"
8181
threads="pthreads"
82-
LIBS="${LIBS} -framework IOKit -framework CoreFoundation -framework AppKit"
82+
LIBS="${LIBS} -framework IOKit -framework CoreFoundation"
8383
;;
8484
*-freebsd*)
8585
AC_MSG_RESULT([ (FreeBSD back-end)])

src/hidapi/mac/Makefile-manual

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ COBJS=hid.o
1414
CPPOBJS=../hidtest/hidtest.o
1515
OBJS=$(COBJS) $(CPPOBJS)
1616
CFLAGS+=-I../hidapi -Wall -g -c
17-
LIBS=-framework IOKit -framework CoreFoundation -framework AppKit
17+
LIBS=-framework IOKit -framework CoreFoundation
1818

1919

2020
hidtest: $(OBJS)

src/hidapi/mac/hid.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737

3838
#define VALVE_USB_VID 0x28DE
3939

40-
/* As defined in AppKit.h, but we don't need the entire AppKit for a single constant. */
41-
extern const double NSAppKitVersionNumber;
42-
4340
/* Barrier implementation because Mac OSX doesn't have pthread_barrier.
4441
It also doesn't have clock_gettime(). So much for POSIX and SUSv2.
4542
This implementation came from Brent Priddy and was posted on
@@ -134,7 +131,6 @@ struct hid_device_list_node
134131
};
135132

136133
static IOHIDManagerRef hid_mgr = 0x0;
137-
static int is_macos_10_10_or_greater = 0;
138134
static struct hid_device_list_node *device_list = 0x0;
139135

140136
static hid_device *new_hid_device(void)
@@ -489,7 +485,6 @@ static int init_hid_manager(void)
489485
int HID_API_EXPORT hid_init(void)
490486
{
491487
if (!hid_mgr) {
492-
is_macos_10_10_or_greater = (NSAppKitVersionNumber >= 1343); /* NSAppKitVersionNumber10_10 */
493488
return init_hid_manager();
494489
}
495490

@@ -1143,10 +1138,8 @@ void HID_API_EXPORT hid_close(hid_device *dev)
11431138
if (!dev)
11441139
return;
11451140

1146-
/* Disconnect the report callback before close.
1147-
See comment below.
1148-
*/
1149-
if (is_macos_10_10_or_greater || !dev->disconnected) {
1141+
/* Disconnect the report callback before close. */
1142+
if (!dev->disconnected) {
11501143
IOHIDDeviceRegisterInputReportCallback(
11511144
dev->device_handle, dev->input_report_buf, dev->max_input_report_len,
11521145
NULL, dev);
@@ -1169,14 +1162,8 @@ void HID_API_EXPORT hid_close(hid_device *dev)
11691162

11701163
/* Close the OS handle to the device, but only if it's not
11711164
been unplugged. If it's been unplugged, then calling
1172-
IOHIDDeviceClose() will crash.
1173-
1174-
UPD: The crash part was true in/until some version of macOS.
1175-
Starting with macOS 10.15, there is an opposite effect in some environments:
1176-
crash happenes if IOHIDDeviceClose() is not called.
1177-
Not leaking a resource in all tested environments.
1178-
*/
1179-
if (is_macos_10_10_or_greater || !dev->disconnected) {
1165+
IOHIDDeviceClose() will crash. */
1166+
if (!dev->disconnected) {
11801167
IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone);
11811168
}
11821169

0 commit comments

Comments
 (0)