Commit 190adeb
committed
usb1: Make libusb_device_p a c_void_p.
Fixes a pypy3 segfault in USBDevice's finalizer with examples/hotplug.py .
The pointers in the device_p array obtained from libusb_get_device_list are
visibly not copied to the ctypes objects created while iterating the list.
Once the list is freed by libusb_free_device_list, those ctypes pointers
objects are reading the memory address from a freed memory location. With
c_void_p, the iteration produces regular python integers, which forces the
interpreter to get its own copy, which then survives list free.
Unfortunately, this removes a ctypes typecheck on every function taking
a libusb_device_p parameter.1 parent 754c0bc commit 190adeb
2 files changed
Lines changed: 5 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2255 | 2255 | | |
2256 | 2256 | | |
2257 | 2257 | | |
2258 | | - | |
2259 | | - | |
2260 | | - | |
2261 | | - | |
2262 | | - | |
2263 | 2258 | | |
2264 | 2259 | | |
2265 | | - | |
| 2260 | + | |
2266 | 2261 | | |
2267 | 2262 | | |
2268 | 2263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
971 | 971 | | |
972 | 972 | | |
973 | 973 | | |
974 | | - | |
975 | | - | |
976 | | - | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
977 | 978 | | |
978 | 979 | | |
979 | 980 | | |
| |||
0 commit comments