From fa751600bf9b477083c7fb90906cd3f5c05be800 Mon Sep 17 00:00:00 2001 From: Dmitry Kychanov Date: Mon, 1 Jul 2024 12:02:05 +0400 Subject: [PATCH] Resolve crash due to libraries unloading too early --- hidtest/test.c | 9 +++++++-- windows/hid.c | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hidtest/test.c b/hidtest/test.c index d2be2cf61..3667a5756 100644 --- a/hidtest/test.c +++ b/hidtest/test.c @@ -457,6 +457,9 @@ void test_hotplug_deadlocks(void) hid_hotplug_register_callback(0, 0, HID_API_HOTPLUG_EVENT_DEVICE_ARRIVED | HID_API_HOTPLUG_EVENT_DEVICE_LEFT, HID_API_HOTPLUG_ENUMERATE, cb1_func, NULL, &cb1_handle); printf("Test finished successfully (at least no deadlocks were found)\n"); + + // Intentionally leave a callback registered to test how hid_exit handles it + //hid_hotplug_deregister_callback(cb2_handle); } @@ -508,9 +511,11 @@ void interactive_loop(void) test_device(); break; case '4': - test_hotplug_deadlocks(); + test_hotplug_deadlocks(); + break; case 'Q': - break; + printf("Quitting.\n"); + return; default: printf("Command not recognized\n"); break; diff --git a/windows/hid.c b/windows/hid.c index e5585028f..4d3fb409b 100644 --- a/windows/hid.c +++ b/windows/hid.c @@ -519,14 +519,14 @@ static void hid_internal_hotplug_exit() int HID_API_EXPORT hid_exit(void) { + hid_internal_hotplug_exit(); + #ifndef HIDAPI_USE_DDK free_library_handles(); hidapi_initialized = FALSE; #endif register_global_error(NULL); - hid_internal_hotplug_exit(); - return 0; }