Commit 09143cc
Fix devs cleanup: protect teardown under hid_hotplug_context.mutex
The struct comment on hid_hotplug_context.devs claimed it was protected
by hid_hotplug_context.mutex, but the final cleanup in callback_thread
ran under only callback_thread.mutex — inconsistent with all other
accesses (process_hotplug_event, hid_hotplug_register_callback) that
hold hid_hotplug_context.mutex when reading or writing devs.
Move the free to hid_internal_hotplug_cleanup(), after
hidapi_thread_join(libusb_thread) returns, so every access to devs —
including the teardown free — happens while holding the context mutex.
Also fix a leak on the hid_hotplug_register_callback error path: when
libusb_hotplug_register_callback fails, no hotplug thread is created,
so hid_internal_hotplug_cleanup() can't be used to unwind the devs list
assigned by the preceding hid_enumerate() call. Free it inline on that
path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7223ef7 commit 09143cc
1 file changed
Lines changed: 13 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
177 | | - | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| |||
586 | 587 | | |
587 | 588 | | |
588 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
589 | 595 | | |
590 | 596 | | |
591 | 597 | | |
| |||
1250 | 1256 | | |
1251 | 1257 | | |
1252 | 1258 | | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | 1259 | | |
1258 | 1260 | | |
1259 | 1261 | | |
| |||
1362 | 1364 | | |
1363 | 1365 | | |
1364 | 1366 | | |
1365 | | - | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
1366 | 1370 | | |
| 1371 | + | |
| 1372 | + | |
1367 | 1373 | | |
1368 | 1374 | | |
1369 | 1375 | | |
| |||
0 commit comments