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:
zagrodzki
2017-09-04 12:52:42 +02:00
committed by GitHub
parent 757722bf8e
commit cf19eb7001

View File

@@ -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) {