[Pcsclite-cvs-commit] r6674 - trunk/Drivers/ccid/src
ludovic.rousseau at free.fr
ludovic.rousseau at free.fr
Sun Jul 28 09:30:19 UTC 2013
Author: rousseau
Date: 2013-06-28 08:56:07 +0000 (Fri, 28 Jun 2013)
New Revision: 6674
Modified:
trunk/Drivers/ccid/src/ccid_usb.c
Log:
Call libusb_exit() when needed
Starting with libusbx 1.0.16 a hotplug thread is created by libusb. We
must cleanly stop the thread or bad thing can happen (crash on Mac OS X
for exampple)
Modified: trunk/Drivers/ccid/src/ccid_usb.c
===================================================================
--- trunk/Drivers/ccid/src/ccid_usb.c 2013-06-28 08:43:02 UTC (rev 6673)
+++ trunk/Drivers/ccid/src/ccid_usb.c 2013-06-28 08:56:07 UTC (rev 6674)
@@ -142,7 +142,29 @@
/* data rates supported by the secondary slots on the GemCore Pos Pro & SIM Pro */
unsigned int SerialCustomDataRates[] = { GEMPLUS_CUSTOM_DATA_RATES, 0 };
+/*****************************************************************************
+ *
+ * close_libusb_if_needed
+ *
+ ****************************************************************************/
+static void close_libusb_if_needed(void)
+{
+ int i, to_exit = TRUE;
+ /* if at least 1 reader is still in use we do not exit libusb */
+ for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
+ {
+ if (usbDevice[i].dev_handle != NULL)
+ to_exit = FALSE;
+ }
+
+ if (to_exit)
+ {
+ DEBUG_INFO("libusb_exit");
+ libusb_exit(ctx);
+ }
+} /* close_libusb_if_needed */
+
/*****************************************************************************
*
* OpenUSB
@@ -612,8 +634,7 @@
end:
if (usbDevice[reader_index].dev_handle == NULL)
{
- /* does not work for libusb <= 1.0.8 */
- /* libusb_exit(ctx); */
+ close_libusb_if_needed();
if (claim_failed)
return STATUS_COMM_ERROR;
return STATUS_NO_SUCH_DEVICE;
@@ -785,15 +806,14 @@
(void)libusb_release_interface(usbDevice[reader_index].dev_handle,
usbDevice[reader_index].interface);
(void)libusb_close(usbDevice[reader_index].dev_handle);
-
- /* does not work for libusb <= 1.0.8 */
- /* libusb_exit(ctx); */
}
/* mark the resource unused */
usbDevice[reader_index].dev_handle = NULL;
usbDevice[reader_index].interface = 0;
+ close_libusb_if_needed();
+
return STATUS_SUCCESS;
} /* CloseUSB */
More information about the Pcsclite-cvs-commit
mailing list