From ad8d94979fd7fa4f0fa66b923e64f1067af60497 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 18 Oct 2013 06:55:30 +1100 Subject: [PATCH] Destroy cgsems used after transfers to not leave open files on osx. --- usbutils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/usbutils.c b/usbutils.c index 0beddb53..d5fb26b7 100644 --- a/usbutils.c +++ b/usbutils.c @@ -2219,6 +2219,12 @@ static void init_usb_transfer(struct usb_transfer *ut) ut->transfer->user_data = ut; } +static void complete_usb_transfer(struct usb_transfer *ut) +{ + cgsem_destroy(&ut->cgsem); + libusb_free_transfer(ut->transfer); +} + static void LIBUSB_CALL transfer_callback(struct libusb_transfer *transfer) { struct usb_transfer *ut = transfer->user_data; @@ -2306,7 +2312,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo, errn = errno; if (!err) err = callback_wait(&ut, transferred, timeout); - libusb_free_transfer(ut.transfer); + complete_usb_transfer(&ut); STATS_TIMEVAL(&tv_finish); USB_STATS(cgpu, &tv_start, &tv_finish, err, mode, cmd, seq, timeout); @@ -2754,7 +2760,7 @@ static int usb_control_transfer(struct cgpu_info *cgpu, libusb_device_handle *de if ((err) == LIBUSB_TRANSFER_CANCELLED) err = LIBUSB_ERROR_TIMEOUT; out: - libusb_free_transfer(ut.transfer); + complete_usb_transfer(&ut); return err; }