From: Richard Levitte Date: Fri, 18 Sep 2009 12:03:56 +0000 (+0000) Subject: Make sure to handle cases when the backend is stopped before being initialised X-Git-Tag: yubikey-personalisation_1.3.5-1~4^2~51 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2708556b59994c253756ed49f568c932b97da929;p=yubikey-personalization.old Make sure to handle cases when the backend is stopped before being initialised --- diff --git a/ykcore/ykcore_libusb-1.0.c b/ykcore/ykcore_libusb-1.0.c index 7fc9aee..35f7bb0 100644 --- a/ykcore/ykcore_libusb-1.0.c +++ b/ykcore/ykcore_libusb-1.0.c @@ -41,6 +41,7 @@ #define HID_SET_REPORT 0x09 static int ykl_errno; +static int libusb_inited = 0; /************************************************************************* ** function _ykusb_write ** @@ -135,13 +136,18 @@ int _ykusb_read(void *dev, int report_type, int report_number, int _ykusb_start(void) { libusb_init(NULL); + libusb_inited = 1; return 1; } extern int _ykusb_stop(void) { - libusb_exit(NULL); - return 1; + if (libusb_inited == 1) { + libusb_exit(NULL); + return 1; + } + yk_errno = YK_EUSBERR; + return 0; } void *_ykusb_open_device(int vendor_id, int product_id)