Fix LibUSB v1.0 compliancy.

1) We need to allow the USB callback to free the USB transfer itself.
2) The USB transfer buffer should only be automatically freed when
freeing the USB transfer.

Fixed by:	hselasky
Submitted by:	Gustau Perez i Querol
Approved by:	thompsa (mentor)
This commit is contained in:
Hans Petter Selasky 2010-11-13 19:25:11 +00:00
parent f10ff4abcd
commit 31f7072c3b
2 changed files with 11 additions and 4 deletions

View File

@ -800,6 +800,10 @@ libusb_free_transfer(struct libusb_transfer *uxfer)
if (uxfer == NULL)
return; /* be NULL safe */
/* check if we should free the transfer buffer */
if (uxfer->flags & LIBUSB_TRANSFER_FREE_BUFFER)
free(uxfer->buffer);
sxfer = (struct libusb_super_transfer *)(
(uint8_t *)uxfer - sizeof(*sxfer));

View File

@ -187,6 +187,8 @@ do_done:
/* Do all done callbacks */
while ((sxfer = TAILQ_FIRST(&ctx->tr_done))) {
uint8_t flags;
TAILQ_REMOVE(&ctx->tr_done, sxfer, entry);
sxfer->entry.tqe_prev = NULL;
@ -197,13 +199,14 @@ do_done:
uxfer = (struct libusb_transfer *)(
((uint8_t *)sxfer) + sizeof(*sxfer));
/* Allow the callback to free the transfer itself. */
flags = uxfer->flags;
if (uxfer->callback != NULL)
(uxfer->callback) (uxfer);
if (uxfer->flags & LIBUSB_TRANSFER_FREE_BUFFER)
free(uxfer->buffer);
if (uxfer->flags & LIBUSB_TRANSFER_FREE_TRANSFER)
/* Check if the USB transfer should be automatically freed. */
if (flags & LIBUSB_TRANSFER_FREE_TRANSFER)
libusb_free_transfer(uxfer);
CTX_LOCK(ctx);