Fix leakage pathes for V1
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Sat, 10 Dec 2011 17:08:06 +0000 (18:08 +0100)
committerUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Sat, 10 Dec 2011 17:08:06 +0000 (18:08 +0100)
src/stlink-sg.c

index 50c0db50555b621b99b81e5fb2f1b5c5929ee606..394417b1819f4e6075b7f5060cd8021fab128008 100644 (file)
@@ -857,6 +857,7 @@ static stlink_t* stlink_open(const int verbose) {
     if (slsg->usb_handle == NULL) {
         WLOG("Failed to find an stlink v1 by VID:PID\n");
         libusb_close(slsg->usb_handle);
+        libusb_exit(slsg->libusb_ctx);
         free(sl);
         free(slsg);
         return NULL;
@@ -871,6 +872,7 @@ static stlink_t* stlink_open(const int verbose) {
         if (r < 0) {
             WLOG("libusb_detach_kernel_driver(() error %s\n", strerror(-r));
             libusb_close(slsg->usb_handle);
+            libusb_exit(slsg->libusb_ctx);
             free(sl);
             free(slsg);
             return NULL;
@@ -883,6 +885,7 @@ static stlink_t* stlink_open(const int verbose) {
         /* this may fail for a previous configured device */
         WLOG("libusb_get_configuration()\n");
         libusb_close(slsg->usb_handle);
+        libusb_exit(slsg->libusb_ctx);
         free(sl);
         free(slsg);
         return NULL;
@@ -897,6 +900,7 @@ static stlink_t* stlink_open(const int verbose) {
             /* this may fail for a previous configured device */
             WLOG("libusb_set_configuration() failed\n");
             libusb_close(slsg->usb_handle);
+            libusb_exit(slsg->libusb_ctx);
             free(sl);
             free(slsg);
             return NULL;
@@ -906,6 +910,7 @@ static stlink_t* stlink_open(const int verbose) {
     if (libusb_claim_interface(slsg->usb_handle, 0)) {
         WLOG("libusb_claim_interface() failed\n");
         libusb_close(slsg->usb_handle);
+        libusb_exit(slsg->libusb_ctx);
         free(sl);
         free(slsg);
         return NULL;