Review error handling paths in register_callback for Windows backend #785

Open
opened 2026-03-31 08:16:12 -05:00 by Youw · 0 comments
Youw commented 2026-03-31 08:16:12 -05:00 (Migrated from github.com)

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)

> 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)](https://github.com/libusb/hidapi/pull/674/changes#r2870009022)_ Also: [#674 (comment)](https://github.com/libusb/hidapi/pull/674/changes#r2870008985)
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#785
No description provided.