Skip to content

Commit e87ae64

Browse files
committed
software/usb/device: endpoint should keep reference to the usb device
without reference to the device, and depending on the invocation the usb device may be collected by the garbage collector while the usb endpoint is still in use. this causes the following error which is difficult to trace: python: core.c:1278: libusb_ref_device: Assertion `refcnt >= 2' failed. now the endpoint keeps a reference to the device preventing it to be freed
1 parent ba52bef commit e87ae64

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lambdalib/software/usb/device.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88

99
class USBEndpoint():
10-
def __init__(self, handle, size, num, asynchronous=True, context=None, timeout=1000):
10+
def __init__(self, handle, size, num, asynchronous=True, context=None,
11+
timeout=1000, device=None):
1112
self.handle = handle
1213
self.size = size
1314
self.num = num
1415
self.asynchronous = asynchronous
1516
self.context = context
1617
self.timeout = timeout
18+
self.device = device
1719

1820
# function alias
1921
self.write = self.send
@@ -98,7 +100,8 @@ def control_read(self, *args):
98100

99101
def get_endpoint(self, num, asynchronous=True):
100102
return USBEndpoint(self.handle, self.bulksize, num,
101-
asynchronous=asynchronous, context=self.context)
103+
asynchronous=asynchronous, context=self.context,
104+
device=self)
102105

103106
def __del__(self):
104107
if self.handle:

0 commit comments

Comments
 (0)