diff --git a/windows/hid.c b/windows/hid.c index b1d8d2620..bb800e080 100644 --- a/windows/hid.c +++ b/windows/hid.c @@ -386,6 +386,9 @@ int HID_API_EXPORT hid_init(void) register_global_error(NULL); if (!hid_hotplug_context.mutex) { hid_hotplug_context.mutex = CreateMutexA(NULL, FALSE, NULL); + if(!hid_hotplug_context.mutex) { + register_global_error(L"Failed to create hotplug management mutex"); + } } #ifndef HIDAPI_USE_DDK if (!hidapi_initialized) { @@ -410,9 +413,11 @@ static void hid_internal_cleanup_hotplugs() hid_hotplug_context.devs = NULL; } - if (CM_Unregister_Notification(hid_hotplug_context.notify_handle) != CR_SUCCESS) { - register_global_error(L"hid_hotplug_deregister_callback/CM_Unregister_Notification"); - return; + if (hid_hotplug_context.notify_handle) { + if (CM_Unregister_Notification(hid_hotplug_context.notify_handle) != CR_SUCCESS) { + register_global_error(L"hid_hotplug_deregister_callback/CM_Unregister_Notification"); + return; + } } hid_hotplug_context.notify_handle = NULL;