diff options
author | David Moore <dcm@acm.org> | 2009-01-11 21:46:17 -0800 |
---|---|---|
committer | Daniel Drake <dsd@gentoo.org> | 2009-01-12 17:58:53 +0000 |
commit | b9ca960f2ba271d2b1a58e22b7c70464d69f6c8a (patch) | |
tree | be2eff6b2d80dc4a759b5c2c70c983330fc94221 /libusb/io.c | |
parent | d2a8ec2da8abcd8f4648ed118da16191011982dd (diff) | |
download | libusb-b9ca960f2ba271d2b1a58e22b7c70464d69f6c8a.tar.gz |
Prevent transfer from being submitted twice or improperly canceled
This ensures that tpriv->urbs and tpriv->iso_urbs are always set to NULL
whenever a transfer is not submitted. In this way, submit_*_transfer()
and cancel_*_transfer() can error check to ensure that the transfer is
in the correct state to be either submitted or canceled, preventing
potential memory leaks or double frees.
Signed-off-by: David Moore <dcm@acm.org>
Diffstat (limited to 'libusb/io.c')
-rw-r--r-- | libusb/io.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/libusb/io.c b/libusb/io.c index 89a94a2..320bc4b 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1101,12 +1101,10 @@ API_EXPORTED void libusb_free_transfer(struct libusb_transfer *transfer) * Submit a transfer. This function will fire off the USB transfer and then * return immediately. * - * It is undefined behaviour to submit a transfer that has already been - * submitted but has not yet completed. - * * \param transfer the transfer to submit * \returns 0 on success * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected + * \returns LIBUSB_ERROR_BUSY if the transfer has already been submitted. * \returns another LIBUSB_ERROR code on other failure */ API_EXPORTED int libusb_submit_transfer(struct libusb_transfer *transfer) @@ -1134,8 +1132,6 @@ API_EXPORTED int libusb_submit_transfer(struct libusb_transfer *transfer) /** \ingroup asyncio * Asynchronously cancel a previously submitted transfer. - * It is undefined behaviour to call this function on a transfer that is - * already being cancelled or has already completed. * This function returns immediately, but this does not indicate cancellation * is complete. Your callback function will be invoked at some later time * with a transfer status of @@ -1144,6 +1140,8 @@ API_EXPORTED int libusb_submit_transfer(struct libusb_transfer *transfer) * * \param transfer the transfer to cancel * \returns 0 on success + * \returns LIBUSB_ERROR_NOT_FOUND if the transfer is already complete or + * cancelled. * \returns a LIBUSB_ERROR code on failure */ API_EXPORTED int libusb_cancel_transfer(struct libusb_transfer *transfer) |