Skip to content

Commit 9f2c472

Browse files
YouwCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 91145c9 commit 9f2c472

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

libusb/hid.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ static int hid_libusb_hotplug_callback(libusb_context *ctx, libusb_device *devic
11351135

11361136
struct hid_hotplug_queue* msg = calloc(1, sizeof(struct hid_hotplug_queue));
11371137
if (NULL == msg) {
1138+
libusb_unref_device(device);
11381139
return 0;
11391140
}
11401141

@@ -1195,8 +1196,8 @@ static void process_hotplug_event(struct hid_hotplug_queue* msg)
11951196
*current = (*current)->next;
11961197
info->next = NULL;
11971198
hid_internal_invoke_callbacks(info, HID_API_HOTPLUG_EVENT_DEVICE_LEFT);
1198-
/* Free every removed device */
1199-
free(info);
1199+
/* Free every removed device (and its internal allocations) */
1200+
hid_free_enumeration(info);
12001201
} else {
12011202
current = &info->next;
12021203
}

linux/hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ static void* hotplug_thread(void* user_data)
12761276
info->next = NULL;
12771277
hid_internal_invoke_callbacks(info, HID_API_HOTPLUG_EVENT_DEVICE_LEFT);
12781278
/* Free every removed device */
1279-
free(info);
1279+
hid_free_enumeration(info);
12801280
} else {
12811281
current = &info->next;
12821282
}

mac/hid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ static void hid_internal_hotplug_disconnect_callback(void *context, IOReturn res
10771077
info->next = NULL;
10781078
hid_internal_invoke_callbacks(info, HID_API_HOTPLUG_EVENT_DEVICE_LEFT);
10791079
/* Free every removed device */
1080-
free(info);
1080+
hid_free_enumeration(info);
10811081
} else {
10821082
current = &info->next;
10831083
}

windows/hid.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,9 @@ DWORD WINAPI hid_internal_notify_callback(HCMNOTIFICATION notify, PVOID context,
11761176

11771177
/* Free removed device */
11781178
if (hotplug_event == HID_API_HOTPLUG_EVENT_DEVICE_LEFT) {
1179-
free(device);
1179+
/* Ensure only this node is freed by hid_free_enumeration() */
1180+
device->next = NULL;
1181+
hid_free_enumeration(device);
11801182
}
11811183

11821184
/* Remove any callbacks that were marked for removal and stop the notification if none are left */

0 commit comments

Comments
 (0)