Skip to content

Commit

Permalink
Resolve crash due to libraries unloading too early
Browse files Browse the repository at this point in the history
  • Loading branch information
k1-801 committed Jul 1, 2024
1 parent d80a9cf commit fa75160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions hidtest/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit fa75160

Please sign in to comment.