On the error returns in the first-callback path (e.g., notify_handle != NULL or CM_Register_Notification(...) != CR_SUCCESS), the newly allocated hotplug_cb (and the devs list from hid_enumerate) are not freed, and hid_hotplug_context.hotplug_cbs may already be set to hotplug_cb. This leaves the hotplug context in a partially-initialized state and leaks memory; the error path should undo any state changes and free allocations before returning.
Originally posted by @Copilot in #674 (comment)
Also: #674 (comment)