Linux: Fix #81 URB double free race condition on device disconnect
authorPete Batard <pbatard@gmail.com>
Thu, 16 Jun 2011 09:49:13 +0000 (10:49 +0100)
committerPeter Stuge <peter@stuge.se>
Mon, 17 Oct 2011 14:25:50 +0000 (16:25 +0200)
commit737ba04ea40f19564b445fbb489907529e75edc9
treefb86afb43f502d542b87b65ecc5ba1e0394c2cd9
parent1b0f758a334d78d3832d17d694ac0c931da36050
Linux: Fix #81 URB double free race condition on device disconnect

A submitted transfer that has just been failed by the kernel could be
picked up by an event handler to be cleaned up, where freeing of URB
memory would race with the submit function doing it's own cleanup and
freeing as a result of the submit failing.

libusb_submit_transfer() always holds itransfer->lock, so the race can
be avoided by taking that lock also in the cleanup path and checking
that the URB memory has not already been freed before freeing it there.

As http://libusb.org/ticket/81#comment:14 notes there is still another
possible, but unlikely, race condition between libusb_submit_transfer()
and an event handling thread. That will require more work to solve.

[stuge: Add check in cleanup path that URBs have not already been freed]
libusb/os/linux_usbfs.c