core: Fix handling of duplicate transfer submission/cancellation
authorChris Dickens <christopher.a.dickens@gmail.com>
Thu, 8 Jan 2015 20:45:56 +0000 (12:45 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Sun, 11 Jan 2015 08:24:46 +0000 (00:24 -0800)
commit859d6a961e11171ce06d2e5b761ec096a3d0bd26
treeb012d0f81acee8855a28b43ea258045b67f202ba
parent63a440f154364f0d306387d82ae6ae5f2ca1ab61
core: Fix handling of duplicate transfer submission/cancellation

In the docs, we claim to report LIBUSB_ERROR_BUSY if submitting a
transfer that has already been submitted. Linux was the only backend
that actually checked and reported this, but unfortunately the code
in libusb_submit_transfer() resulted in a segfault. This is because
submission failure would delete the (active) transfer from the
flying_transfers list, and when the transfer finally completes it
would be deleted from the flying_transfers list a second time.

Instead of modifying each backend to check for a busy transfer, this
patch adds a flag to indicate when a transfer is in-flight. The core
library will check this flag and return LIBUSB_ERROR_BUSY immediately.

This patch also modifies libusb_cancel_transfer() to check that a
transfer is in-flight before cancelling and to check that a transfer
has not already been cancelled, returning LIBUSB_ERROR_NOT_FOUND in
both cases.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/io.c
libusb/libusbi.h
libusb/os/linux_usbfs.c
libusb/version_nano.h