Fix a race condition in reuse of the same malloc result (#15)
In free(), remove Go references to the C memory before the C memory itself is released. That ensures that a concurrent alloc() will not try to insert the same pointer into the map that was not yet removed.
This commit is contained in:
@@ -467,10 +467,10 @@ func (libusbImpl) data(t *libusbTransfer) (int, TransferStatus) {
|
||||
}
|
||||
|
||||
func (libusbImpl) free(t *libusbTransfer) {
|
||||
C.gousb_free_transfer_and_buffer((*C.struct_libusb_transfer)(t))
|
||||
xferDoneMap.Lock()
|
||||
delete(xferDoneMap.m, t)
|
||||
xferDoneMap.Unlock()
|
||||
C.gousb_free_transfer_and_buffer((*C.struct_libusb_transfer)(t))
|
||||
}
|
||||
|
||||
func (libusbImpl) setIsoPacketLengths(t *libusbTransfer, length uint32) {
|
||||
|
Reference in New Issue
Block a user