Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to claim interface multiple times #16

Closed
ssoloski opened this issue Jun 2, 2014 · 26 comments
Closed

Unable to claim interface multiple times #16

ssoloski opened this issue Jun 2, 2014 · 26 comments
Labels

Comments

@ssoloski
Copy link

ssoloski commented Jun 2, 2014

When performing multiple open/close cycles and claiming an interface, libusbK fails after 32 times with Access Denied error.

This error was found during unit testing of my code using libFTDI; further testing using only libusb 1.0.19-rc2 code reproduces the error. This happens under Win8.1 x64; USB drivers are installed using libusbK-inf-wizard. If I install only the libusbK driver, the problems occurs. I've installed the driver on both the composite device (an FT2232H chip) and on Interface A; the error occurs either way.

If I install the WinUSB driver, the problem occurs... but if you then remove the libusb0 and libusbK dll files (installed by the inf-wizard) and only use the WinUSB driver the error does not occur.

I have a sample program to demonstrate the issue; not sure how to attach it here though. Let me know if you need additional info...

Steve

@mcuee
Copy link
Member

mcuee commented Jun 3, 2014

Please post the code here, Thanks. You can even enable syntax highlighting using the github markdown syntax.
https://help.github.com/articles/github-flavored-markdown

@mcuee
Copy link
Member

mcuee commented Jun 3, 2014

The original thread in libftdi mailing list.
http://developer.intra2net.com/mailarchive/html/libftdi/2014/msg00161.html

With libusbK.dll, the test program (with libftdi) will fail to autoclaim.

libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0
(required to claim 1 with WinUSB): [84] Storage to process this request is not available.

@ssoloski
Copy link
Author

ssoloski commented Jun 3, 2014

Here's an example program the will fail after 32 opens when using libusbK. If you use WinUSB (with no libusbK dlls on the system) it will performt he open all 50 times. I noticed this issue under libFTDI trying to open Interface B multiple time; this code also appears to fail opening Interface A. The logic of the code is taken from the logic of libFTDI.

Steve

/*
 * check_libusb.c
 *
 *  Created on: Jun 2, 2014
 *      Author: Steve
 */

#include <stdio.h>
#include <stdlib.h>
#include <libusb.h>
#include <errno.h>

#define VID 0x0403
#define PID 0x7C38

#define INTERFACE_A     0
#define INTERFACE_B     1

#define SIO_RESET          0 /* Reset the port */
#define FTDI_DEVICE_OUT_REQTYPE (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT)
#define SIO_RESET_REQUEST             SIO_RESET
#define SIO_RESET_SIO 0
#define EPERM 1

static int find_device(libusb_context *ctx, int vid, int pid, int interface, libusb_device_handle **foundDev);
static int open_device(libusb_device *dev, libusb_device_handle **hDev, int interface);

int main(int argc, char **argv) {
    int i, err;
    libusb_context *ctx;
    libusb_device_handle *foundDev;

    for (i=0; i<50; i++) {
        printf("Open count %d of 50\n", i);

        err = libusb_init(&ctx);
        if (err < 0) {
            printf("Error initializing libusb: %s\n", libusb_strerror(err));
            ctx = NULL;
            break;
        }

        // find and open the device
        err = find_device(ctx, VID, PID, INTERFACE_A, &foundDev);
        if (err == 0) {
            if (foundDev) {
                libusb_close(foundDev);
                foundDev = NULL;
            }
            else {
                printf("No device found!\n");
                break;
            }
        }
        else {
            printf("Error finding device!\n");
            break;
        }

        // exit libusb
        if (ctx) {
            libusb_exit(ctx);
            ctx = NULL;
        }
    }

    // exit libusb if not done earlier
    if (ctx) {
        libusb_exit(ctx);
        ctx = NULL;
    }


    return err;
}

static int find_device(libusb_context *ctx, int vid, int pid, int interface, libusb_device_handle **foundDev) {
    int i, err;
    libusb_device *dev;
    libusb_device **devs;
    libusb_device_handle *hDev;

    // get the list of devices
    err = libusb_get_device_list(ctx, &devs);
    if (err < 0) {
        printf("Error getting device list: %s\n", libusb_strerror(err));
        devs = NULL;
        return err;
    }

    // find our device
    while ((dev = devs[i++]) != NULL) {
        struct libusb_device_descriptor desc;
        int res;

        if (libusb_get_device_descriptor(dev, &desc) < 0) {
            printf("Error getting device descriptor: %s\n", libusb_strerror(err));
            break;
        }

        // if this isn't our device, just continue
        if (desc.idVendor != vid || desc.idProduct != pid) {
            continue;
        }

        // open the device to check for serial number match
        err = libusb_open(dev, &hDev);
        if (err < 0) {
            printf("Error opening device for serial number check: %s\n", libusb_strerror(err));
            break;
        }

        // we're not checking for matching product and serial numbers,
        // so just close the device
        libusb_close(hDev);

        // this device matches our VID and PID, so open it
        err = open_device(dev, foundDev, interface);
        break;
    }

    // free the device list
    libusb_free_device_list(devs, 1);

    return err;
}

static int open_device(libusb_device *dev, libusb_device_handle **hDev, int interface) {
    int err;
    struct libusb_device_descriptor desc;
    struct libusb_config_descriptor *config0;
    int cfg, cfg0, detach_errno = 0;

    err = libusb_open(dev, hDev);
    if (err < 0) {
        *hDev = NULL;
        puts(libusb_strerror(err));
        return err;
    }

    err = libusb_get_device_descriptor(dev, &desc);
    if (err < 0) {
        printf("Error getting device descriptor: %s\n", libusb_strerror(err));
        return err;
    }

    err = libusb_get_config_descriptor(dev, 0, &config0);
    if (err < 0) {
        printf("Error getting config descriptor: %s\n", libusb_strerror(err));
        return err;
    }
    cfg0 = config0->bConfigurationValue;
    libusb_free_config_descriptor(config0);

    // Try to detach ftdi_sio kernel module.
    //
    // The return code is kept in a separate variable and only parsed
    // if usb_set_configuration() or usb_claim_interface() fails as the
    // detach operation might be denied and everything still works fine.
    // Likely scenario is a static ftdi_sio kernel module.
//  if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
    if (1) {
        if (libusb_detach_kernel_driver(*hDev, interface) !=0) {
            detach_errno = errno;
        }
    }

    err = libusb_get_configuration(*hDev, &cfg);
    if (err < 0) {
        printf("Error getting configuration: %s\n", libusb_strerror(err));
        return err;
    }

    // set configuration (needed especially for windows)
    // tolerate EBUSY: one device with one configuration, but two interfaces
    //    and libftdi sessions to both interfaces (e.g. FT2232)
    if (desc.bNumConfigurations > 0 && cfg != cfg0) {
        err = libusb_set_configuration(*hDev, cfg0);
        if (err < 0) {
            libusb_close (*hDev);
            *hDev = NULL;
            if (detach_errno == EPERM) {
                printf("Error setting configuration (EPERM): %s\n", libusb_strerror(err));
                return err;
            }
            else {
                printf("Error setting configuration: %s\n", libusb_strerror(err));
                return err;
            }
        }
    }

    err = libusb_claim_interface(*hDev, interface);
    if (err < 0) {
        libusb_close (*hDev);
        *hDev = NULL;
        if (detach_errno == EPERM) {
            printf("Error claiming interface (EPERM): %s\n", libusb_strerror(err));
            return err;
        }
        else {
            printf("Error claiming interface: %s\n", libusb_strerror(err));
            return err;
        }
    }

    err = libusb_control_transfer(*hDev, FTDI_DEVICE_OUT_REQTYPE,
                                SIO_RESET_REQUEST, SIO_RESET_SIO,
                                interface+1, NULL, 0, 5000);
    if (err < 0) {
        libusb_close (*hDev);
        *hDev = NULL;
        printf("Error resetting device: %s\n", libusb_strerror(err));
        return err;
    }

    // skipped determining max packet size

    // skipped setting buadrate

    return err;
}

@mcuee
Copy link
Member

mcuee commented Jun 4, 2014

Could you post the running log after setting LIBUSB_DEBUG environment variable to be 4? It will be quite a long log but you only need to post the logs containing the initial device list, the 1st successful open and the first failed open.

@mcuee
Copy link
Member

mcuee commented Jun 4, 2014

Somehow I could not run your program under Mac OS X 10.9.3 (can not find device). However, I can run your program under Windows 8.1 x64 and reproduce the issue (with 0403:cff8 device).

Open count 1 of 50
Open count 2 of 50
Open count 3 of 50
Open count 4 of 50
Open count 5 of 50
Open count 6 of 50
Open count 7 of 50
Open count 8 of 50
Open count 9 of 50
Open count 10 of 50
Open count 11 of 50
Open count 12 of 50
Open count 13 of 50
Open count 14 of 50
Open count 15 of 50
Open count 16 of 50
Open count 17 of 50
Open count 18 of 50
Open count 19 of 50
Open count 20 of 50
Open count 21 of 50
Open count 22 of 50
Open count 23 of 50
Open count 24 of 50
Open count 25 of 50
Open count 26 of 50
Open count 27 of 50
Open count 28 of 50
Open count 29 of 50
Open count 30 of 50
Open count 31 of 50
Open count 32 of 50
Error claiming interface: Access denied (insufficient permissions)
Error finding device!

[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000000] [000003ec] libusb: debug [libusb_init] created default context
[ 0.000000] [000003ec] libusb: debug [libusb_init] libusb v1.0.18.10866
[ 0.000000] [000003ec] libusb: debug [setup_cancel_io] Will use CancelIoEx for I/O cancellation
[ 0.015697] [000003ec] libusb: debug [winusbx_init] using libusbK DLL for universal access
[ 0.015697] [000003ec] libusb: debug [winusbx_init] libusbK version: 3.0.7.0
[ 0.015697] [000003ec] libusb: debug [winusbx_init] initalized sub API libusbK
[ 0.015697] [000003ec] libusb: debug [winusbx_init] initalized sub API libusb0
[ 0.015697] [000003ec] libusb: debug [winusbx_init] initalized sub API WinUSB
[ 0.015697] [000009c0] libusb: debug [windows_clock_gettime_threaded] hires timer available (Frequency: 2222537 Hz)
[ 0.015697] [000003ec] libusb: debug [htab_create] using 1021 entries hash table
[ 0.015697] [000003ec] libusb: debug [usbi_add_pollfd] add fd 0 events 1
[ 0.015697] [000003ec] libusb: debug [usbi_add_pollfd] add fd 1 events 1
[ 0.015697] [000003ec] libusb: debug [libusb_get_device_list] 
[ 0.015697] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [3A3]
[ 0.015697] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [124]
[ 0.015697] [000003ec] libusb: debug [get_api_type] driver(s): usbhub
[ 0.015697] [000003ec] libusb: debug [get_api_type] matched driver name against HUB API API
[ 0.015697] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [20D]
[ 0.015697] [000003ec] libusb: debug [get_api_type] driver(s): usbhub
[ 0.015697] [000003ec] libusb: debug [get_api_type] matched driver name against HUB API API
[ 0.015697] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [3C]
[ 0.015697] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [20D] (0.0)
[ 0.015697] [000003ec] libusb: debug [init_device] (bus: 1, addr: 1, depth: 0, port: 0): '\\.\USB#ROOT_HUB#4&65DFC83&0'
[ 0.015697] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [C5]
[ 0.015697] [000003ec] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.031665] [000003ec] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 34 bytes)
[ 0.031665] [000003ec] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 1): '\\.\USB#VID_80EE&PID_0021#5&2D7AE1FF&0&1'
[ 0.031665] [000003ec] libusb: debug [windows_get_device_list] extra GUID: {4567D611-7369-12E4-743B-113D1EFADB0E}
[ 0.031665] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [2A1]
[ 0.031665] [000003ec] libusb: debug [init_device] got bus number from ancestor #2
[ 0.031665] [000003ec] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.062592] [000003ec] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 55 bytes)
[ 0.062592] [000003ec] libusb: debug [init_device] (bus: 2, addr: 2, depth: 1, port: 1): '\\.\USB#VID_0403&PID_CFF8#53T9XDR4'
[ 0.062592] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [3C] (2.0)
[ 0.062592] [000003ec] libusb: debug [init_device] (bus: 2, addr: 1, depth: 0, port: 0): '\\.\USB#ROOT_HUB20#4&280D2B25&0'
[ 0.062592] [000003ec] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.062592] [000003ec] libusb: debug [get_api_type] matched driver name against WinUSB API
[ 0.062592] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [2A1] (2.2)
[ 0.062592] [000003ec] libusb: debug [get_api_type] driver(s): HidUsb
[ 0.062592] [000003ec] libusb: debug [get_api_type] matched driver name against HID API API
[ 0.062592] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [C5] (1.2)
[ 0.062592] [000003ec] libusb: debug [windows_get_device_list] setting HID interface for [C5]:
[ 0.062592] [000003ec] libusb: debug [set_hid_interface] interface[0] = \\.\HID#VID_80EE&PID_0021#6&156F3BA&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.062592] [000003ec] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.062592] [000003ec] libusb: debug [get_api_type] matched driver name against WinUSB API
[ 0.062592] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.062592] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.062592] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.062592] [000003ec] libusb: debug [libusb_open] open 2.2
[ 0.062592] [000003ec] libusb: debug [libusb_close] 
[ 0.062592] [000003ec] libusb: debug [libusb_open] open 2.2
[ 0.062592] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.062592] [000003ec] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.062592] [000003ec] libusb: debug [libusb_detach_kernel_driver] interface 0
[ 0.062592] [000003ec] libusb: debug [libusb_get_configuration] 
[ 0.062592] [000003ec] libusb: debug [libusb_get_configuration] active config 1
[ 0.062592] [000003ec] libusb: debug [libusb_claim_interface] interface 0
[ 0.062592] [000003ec] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.062592] [000003ec] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.062592] [000003ec] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.062592] [000003ec] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 02 to interface 0
[ 0.062592] [000003ec] libusb: debug [winusbx_submit_control_transfer] will use interface 0
[ 0.062592] [000003ec] libusb: debug [usbi_add_pollfd] add fd 2 events 1
[ 0.062592] [000003ec] libusb: debug [libusb_get_next_timeout] next timeout in 4.999101s
[ 0.062592] [000003ec] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.062592] [000003ec] libusb: debug [handle_events] poll() 3 fds with timeout in 5000ms
[ 0.062592] [000003ec] libusb: debug [handle_events] poll() returned 1
[ 0.062592] [000003ec] libusb: debug [windows_handle_events] checking fd 0 with revents = 0000
[ 0.062592] [000003ec] libusb: debug [windows_handle_events] checking fd 1 with revents = 0000
[ 0.062592] [000003ec] libusb: debug [windows_handle_events] checking fd 2 with revents = 0001
[ 0.062592] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 2
[ 0.062592] [000003ec] libusb: debug [windows_transfer_callback] handling I/O completion with errcode 0, size 0
[ 0.062592] [000003ec] libusb: debug [usbi_handle_transfer_completion] transfer 000000000036EEE0 has callback 000000006B606970
[ 0.062592] [000003ec] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.062592] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.062592] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.062592] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.0
[ 0.062592] [000003ec] libusb: debug [libusb_close] 
[ 0.062592] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.2
[ 0.062592] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.062592] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.062592] [000003ec] libusb: debug [libusb_exit] 
[ 0.062592] [000003ec] libusb: debug [libusb_exit] destroying default context
[ 0.062592] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 0
[ 0.062592] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 1
[ 0.062592] [000009c0] libusb: debug [windows_clock_gettime_threaded] timer thread quitting
...
[ 0.625950] [000003ec] libusb: debug [libusb_init] created default context
[ 0.625950] [000003ec] libusb: debug [libusb_init] libusb v1.0.18.10866
[ 0.625950] [000003ec] libusb: debug [setup_cancel_io] Will use CancelIoEx for I/O cancellation
[ 0.625950] [000003ec] libusb: debug [winusbx_init] using libusbK DLL for universal access
[ 0.625950] [000003ec] libusb: debug [winusbx_init] libusbK version: 3.0.7.0
[ 0.625950] [000003ec] libusb: debug [winusbx_init] initalized sub API libusbK
[ 0.625950] [000003ec] libusb: debug [winusbx_init] initalized sub API libusb0
[ 0.625950] [000003ec] libusb: debug [winusbx_init] initalized sub API WinUSB
[ 0.625950] [000007f4] libusb: debug [windows_clock_gettime_threaded] hires timer available (Frequency: 2222537 Hz)
[ 0.625950] [000003ec] libusb: debug [htab_create] using 1021 entries hash table
[ 0.625950] [000003ec] libusb: debug [usbi_add_pollfd] add fd 0 events 1
[ 0.625950] [000003ec] libusb: debug [usbi_add_pollfd] add fd 1 events 1
[ 0.625950] [000003ec] libusb: debug [libusb_get_device_list] 
[ 0.625950] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [3A3]
[ 0.625950] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [124]
[ 0.625950] [000003ec] libusb: debug [get_api_type] driver(s): usbhub
[ 0.625950] [000003ec] libusb: debug [get_api_type] matched driver name against HUB API API
[ 0.625950] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [20D]
[ 0.625950] [000003ec] libusb: debug [get_api_type] driver(s): usbhub
[ 0.625950] [000003ec] libusb: debug [get_api_type] matched driver name against HUB API API
[ 0.625950] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [3C]
[ 0.625950] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [20D] (0.0)
[ 0.625950] [000003ec] libusb: debug [init_device] (bus: 1, addr: 1, depth: 0, port: 0): '\\.\USB#ROOT_HUB#4&65DFC83&0'
[ 0.625950] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [C5]
[ 0.625950] [000003ec] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.640730] [000003ec] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 34 bytes)
[ 0.640730] [000003ec] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 1): '\\.\USB#VID_80EE&PID_0021#5&2D7AE1FF&0&1'
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] extra GUID: {4567D611-7369-12E4-743B-113D1EFADB0E}
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [2A1]
[ 0.640730] [000003ec] libusb: debug [init_device] got bus number from ancestor #2
[ 0.640730] [000003ec] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.640730] [000003ec] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 55 bytes)
[ 0.640730] [000003ec] libusb: debug [init_device] (bus: 2, addr: 2, depth: 1, port: 1): '\\.\USB#VID_0403&PID_CFF8#53T9XDR4'
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [3C] (2.0)
[ 0.640730] [000003ec] libusb: debug [init_device] (bus: 2, addr: 1, depth: 0, port: 0): '\\.\USB#ROOT_HUB20#4&280D2B25&0'
[ 0.640730] [000003ec] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.640730] [000003ec] libusb: debug [get_api_type] matched driver name against WinUSB API
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [2A1] (2.2)
[ 0.640730] [000003ec] libusb: debug [get_api_type] driver(s): HidUsb
[ 0.640730] [000003ec] libusb: debug [get_api_type] matched driver name against HID API API
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [C5] (1.2)
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] setting HID interface for [C5]:
[ 0.640730] [000003ec] libusb: debug [set_hid_interface] interface[0] = \\.\HID#VID_80EE&PID_0021#6&156F3BA&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.640730] [000003ec] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.640730] [000003ec] libusb: debug [get_api_type] matched driver name against WinUSB API
[ 0.640730] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.640730] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.640730] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.640730] [000003ec] libusb: debug [libusb_open] open 2.2
[ 0.640730] [000003ec] libusb: debug [libusb_close] 
[ 0.640730] [000003ec] libusb: debug [libusb_open] open 2.2
[ 0.640730] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.640730] [000003ec] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.640730] [000003ec] libusb: debug [libusb_detach_kernel_driver] interface 0
[ 0.640730] [000003ec] libusb: debug [libusb_get_configuration] 
[ 0.640730] [000003ec] libusb: debug [libusb_get_configuration] active config 1
[ 0.640730] [000003ec] libusb: debug [libusb_claim_interface] interface 0
[ 0.640730] [000003ec] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.640730] [000003ec] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.640730] [000003ec] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.640730] [000003ec] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 02 to interface 0
[ 0.640730] [000003ec] libusb: debug [winusbx_submit_control_transfer] will use interface 0
[ 0.640730] [000003ec] libusb: debug [usbi_add_pollfd] add fd 2 events 1
[ 0.640730] [000003ec] libusb: debug [libusb_get_next_timeout] next timeout in 4.999550s
[ 0.640730] [000003ec] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.640730] [000003ec] libusb: debug [handle_events] poll() 3 fds with timeout in 5000ms
[ 0.640730] [000003ec] libusb: debug [handle_events] poll() returned 1
[ 0.640730] [000003ec] libusb: debug [windows_handle_events] checking fd 0 with revents = 0000
[ 0.640730] [000003ec] libusb: debug [windows_handle_events] checking fd 1 with revents = 0000
[ 0.640730] [000003ec] libusb: debug [windows_handle_events] checking fd 2 with revents = 0001
[ 0.640730] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 2
[ 0.640730] [000003ec] libusb: debug [windows_transfer_callback] handling I/O completion with errcode 0, size 0
[ 0.640730] [000003ec] libusb: debug [usbi_handle_transfer_completion] transfer 000000000036D660 has callback 000000006B606970
[ 0.640730] [000003ec] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.640730] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.640730] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.640730] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.0
[ 0.640730] [000003ec] libusb: debug [libusb_close] 
[ 0.640730] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.2
[ 0.640730] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.640730] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.640730] [000003ec] libusb: debug [libusb_exit] 
[ 0.640730] [000003ec] libusb: debug [libusb_exit] destroying default context
[ 0.640730] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 0
[ 0.640730] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 1
[ 0.640730] [000007f4] libusb: debug [windows_clock_gettime_threaded] timer thread quitting
[ 0.640730] [000003ec] libusb: debug [libusb_init] created default context
[ 0.640730] [000003ec] libusb: debug [libusb_init] libusb v1.0.18.10866
[ 0.640730] [000003ec] libusb: debug [setup_cancel_io] Will use CancelIoEx for I/O cancellation
[ 0.640730] [000003ec] libusb: debug [winusbx_init] using libusbK DLL for universal access
[ 0.640730] [000003ec] libusb: debug [winusbx_init] libusbK version: 3.0.7.0
[ 0.640730] [000003ec] libusb: debug [winusbx_init] initalized sub API libusbK
[ 0.640730] [000003ec] libusb: debug [winusbx_init] initalized sub API libusb0
[ 0.640730] [000003ec] libusb: debug [winusbx_init] initalized sub API WinUSB
[ 0.640730] [000004a0] libusb: debug [windows_clock_gettime_threaded] hires timer available (Frequency: 2222537 Hz)
[ 0.640730] [000003ec] libusb: debug [htab_create] using 1021 entries hash table
[ 0.640730] [000003ec] libusb: debug [usbi_add_pollfd] add fd 0 events 1
[ 0.640730] [000003ec] libusb: debug [usbi_add_pollfd] add fd 1 events 1
[ 0.640730] [000003ec] libusb: debug [libusb_get_device_list] 
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [3A3]
[ 0.640730] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [124]
[ 0.656275] [000003ec] libusb: debug [get_api_type] driver(s): usbhub
[ 0.656275] [000003ec] libusb: debug [get_api_type] matched driver name against HUB API API
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [20D]
[ 0.656275] [000003ec] libusb: debug [get_api_type] driver(s): usbhub
[ 0.656275] [000003ec] libusb: debug [get_api_type] matched driver name against HUB API API
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [3C]
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [20D] (0.0)
[ 0.656275] [000003ec] libusb: debug [init_device] (bus: 1, addr: 1, depth: 0, port: 0): '\\.\USB#ROOT_HUB#4&65DFC83&0'
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [C5]
[ 0.656275] [000003ec] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.656275] [000003ec] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 34 bytes)
[ 0.656275] [000003ec] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 1): '\\.\USB#VID_80EE&PID_0021#5&2D7AE1FF&0&1'
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] extra GUID: {4567D611-7369-12E4-743B-113D1EFADB0E}
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] allocating new device for session [2A1]
[ 0.656275] [000003ec] libusb: debug [init_device] got bus number from ancestor #2
[ 0.656275] [000003ec] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.656275] [000003ec] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 55 bytes)
[ 0.656275] [000003ec] libusb: debug [init_device] (bus: 2, addr: 2, depth: 1, port: 1): '\\.\USB#VID_0403&PID_CFF8#53T9XDR4'
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [3C] (2.0)
[ 0.656275] [000003ec] libusb: debug [init_device] (bus: 2, addr: 1, depth: 0, port: 0): '\\.\USB#ROOT_HUB20#4&280D2B25&0'
[ 0.656275] [000003ec] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.656275] [000003ec] libusb: debug [get_api_type] matched driver name against WinUSB API
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [2A1] (2.2)
[ 0.656275] [000003ec] libusb: debug [get_api_type] driver(s): HidUsb
[ 0.656275] [000003ec] libusb: debug [get_api_type] matched driver name against HID API API
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] found existing device for session [C5] (1.2)
[ 0.656275] [000003ec] libusb: debug [windows_get_device_list] setting HID interface for [C5]:
[ 0.656275] [000003ec] libusb: debug [set_hid_interface] interface[0] = \\.\HID#VID_80EE&PID_0021#6&156F3BA&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.656275] [000003ec] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.656275] [000003ec] libusb: debug [get_api_type] matched driver name against WinUSB API
[ 0.656275] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.656275] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.656275] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.656275] [000003ec] libusb: debug [libusb_open] open 2.2
[ 0.656275] [000003ec] libusb: debug [libusb_close] 
[ 0.656275] [000003ec] libusb: debug [libusb_open] open 2.2
[ 0.656275] [000003ec] libusb: debug [libusb_get_device_descriptor] 
[ 0.656275] [000003ec] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.656275] [000003ec] libusb: debug [libusb_detach_kernel_driver] interface 0
[ 0.656275] [000003ec] libusb: debug [libusb_get_configuration] 
[ 0.656275] [000003ec] libusb: debug [libusb_get_configuration] active config 1
[ 0.656275] [000003ec] libusb: debug [libusb_claim_interface] interface 0
[ 0.656275] [000003ec] libusb: error [winusbx_claim_interface] could not access interface 0: [84] Storage to process this request is not available.
[ 0.656275] [000003ec] libusb: debug [libusb_close] 
[ 0.656275] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.656275] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.656275] [000003ec] libusb: debug [libusb_unref_device] destroy device 1.0
[ 0.656275] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.2
[ 0.656275] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.656275] [000003ec] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.656275] [000003ec] libusb: debug [libusb_exit] 
[ 0.656275] [000003ec] libusb: debug [libusb_exit] destroying default context
[ 0.656275] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 0
[ 0.656275] [000003ec] libusb: debug [usbi_remove_pollfd] remove fd 1
[ 0.656275] [000004a0] libusb: debug [windows_clock_gettime_threaded] timer thread quitting

@mcuee
Copy link
Member

mcuee commented Jun 4, 2014

The above is the debug log with libusb-1.0.18 release, I think it will be similar for latest git as well.

@ssoloski
Copy link
Author

ssoloski commented Jun 4, 2014

Since you were able to recreate the issue, do you still want me to post
my error log?

And I did see that same error for both 1.0.18 and 1.0.19-rc2.

Steve

@mcuee
Copy link
Member

mcuee commented Jun 4, 2014

I think you do not need to post your debug unless you see major differences between my debug log and yours. Thanks.

@mcuee
Copy link
Member

mcuee commented Jun 8, 2014

Still I think your libusb test program has some problems, it causes segmentation fault with the first open already under Ubuntu Linux 14.04 and also quit in the first open with no device find under Mac OS X 10.9.3. So probably there is a problem somewhere in the test program.

@mcuee
Copy link
Member

mcuee commented Jun 8, 2014

On the other hand, the original libftdi test program seems to be okay under Ubuntu Linux 14.04 and Mac OS X 10.9.3.

@pbatard
Copy link
Contributor

pbatard commented Jun 8, 2014

Just so you know, I am not planning to look into this, so hopefully someone else can.

@ssoloski
Copy link
Author

ssoloski commented Jun 9, 2014

Sorry for the late reply; all my code and devices were in the office.

I just ran the test under Fedora 20 x64 with no problems; not sure
what's happening under Ubuntu or Mac. If you want I can create a Ubuntu
environment to test this, but I don't have a Mac available so I can't
help there.

However, the problem is not with the Linux environment - as I mentioned,
I've seen this work just fine on my Fedora machine.

The problem is only showing up under Windows; and then only when libusbK
is in the path. If I install my Windows drivers as WinUSB and don't have
libusbK in the path, I can open the device 50 times without any
problems. With libusbK in the path, it fails after 32 tries.

I'm not sure if this points to an issue with libusbK or not; I don't
know the logic of libusb to know what impact libusbK is having when
opening devices... but it does not fail when only WInUSB is used.

Not sure if this helps any or just confuses the matter; at this point I
don't know if this is a libusb or libusbK issue... I'm willing to try to
help debug it further, but it will take me a bit of time to figure out
the libusb and/or libusbK code. Or if you want me to add some additional
debugging code I can do that as well...

Steve

@mcuee
Copy link
Member

mcuee commented Jun 16, 2014

Just want to add that now I can run your test program under Mac OS X. I need to add " i = 0;" before the following two lines. Maybe it is because of C compiler thingy. After that, there is no problem running this test program under Mac OS X.

// find our device
while ((dev = devs[i++]) != NULL) {

@mcuee
Copy link
Member

mcuee commented Jun 16, 2014

Same thing, once I add that line, it is okay under Ubuntu 14.04.

@mcuee
Copy link
Member

mcuee commented Jun 16, 2014

And of course it does not change the results under Windows 8.1. The same error happens, no matter it is Interface A or B.

@mcuee
Copy link
Member

mcuee commented Jun 16, 2014

I enable libusbK.dll debugging and found out that there are many warnings, no so sure if this is a problem or not.

00000001    0.00000000  [1204]  
00000002    0.00027406  [1204] AllK required contiguous memory = 534200 (64bit) 
00000003    0.00038670  [1204]   8 HotK Handles: HandleSize 2112 PoolSize 16912 (bytes) 
00000004    0.00055610  [1204]   64 LstK Handles: HandleSize 64 PoolSize 4112 (bytes)   
00000005    0.00076054  [1204]   1024 LstInfoK Handles: HandleSize 64 PoolSize 65552 (bytes)    
00000006    0.00097162  [1204]   64 UsbK Handles: HandleSize 96 PoolSize 6160 (bytes)   
00000007    0.00121597  [1204]   32 DevK Handles: HandleSize 112 PoolSize 3600 (bytes)  
00000008    0.00124790  [1204]   4096 OvlK Handles: HandleSize 104 PoolSize 426000 (bytes)  
00000009    0.00141420  [1204]   64 OvlPoolK Handles: HandleSize 96 PoolSize 6160 (bytes)   
00000010    0.00146076  [1204]   32 StmK Handles: HandleSize 176 PoolSize 5648 (bytes)  
00000011    0.00148426  [1204]  
00000012    0.00292906  [1204] Dynamically allocated as needed: 
00000013    0.00383682  [1204]  KLST_DEVINFO = 2596 bytes each  
00000014    0.04136205  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000015    0.05952222  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000016    0.07937951  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000017    0.10077339  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000018    0.11814376  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000019    0.13971680  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000020    0.15879539  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000021    0.18135779  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000022    0.20202085  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000023    0.22231585  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000024    0.24325296  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000025    0.26467657  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000026    0.28480569  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000027    0.30404437  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000028    0.32394245  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000029    0.35161132  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000030    0.38383675  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000031    0.40366298  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000032    0.42198902  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000033    0.44187868  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000034    0.46529964  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000035    0.48468861  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000036    0.50676280  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000037    0.52690834  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000038    0.54918516  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000039    0.56863666  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000040    0.59160084  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000041    0.61537659  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000042    0.63526005  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000043    0.65586591  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000044    0.67800343  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000045    0.69858581  [1204] (libusbK.dll)[k_Init_Version] libusbK.sys v3.0.7.0   
00000046    0.71889764  [1204] [ERR](libusbK.dll)[PoolHandle_Acquire_UsbK] no more internal UsbK handles! (max=64)  
00000047    0.71909189  [1204] [ERR](libusbK.dll)[u_Init_Handle] ErrorCode=00000054h ->PoolHandle_Acquire_UsbK  
00000048    0.71926481  [1204] [ERR](libusbK.dll)[UsbStack_Init] ErrorCode=00000054h ->u_Init_Handle    
00000049    0.72224224  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 0   
00000050    0.72248882  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 1   
00000051    0.72251540  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 2   
00000052    0.72253758  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 3   
00000053    0.72256154  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 4   
00000054    0.72268659  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 5   
00000055    0.72284490  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 6   
00000056    0.72300589  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 7   
00000057    0.72305197  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 8   
00000058    0.72319168  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 9   
00000059    0.72335130  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 10  
00000060    0.72350878  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 11  
00000061    0.72366929  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 12  
00000062    0.72384226  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 13  
00000063    0.72404844  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 14  
00000064    0.72420764  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 15  
00000065    0.72436464  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 16  
00000066    0.72453582  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 17  
00000067    0.72469234  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 18  
00000068    0.72484845  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 19  
00000069    0.72501075  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 20  
00000070    0.72516727  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 21  
00000071    0.72532386  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 22  
00000072    0.72561342  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 23  
00000073    0.72583246  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 24  
00000074    0.72609544  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 25  
00000075    0.72617215  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 26  
00000076    0.72644621  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 27  
00000077    0.72666222  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 28  
00000078    0.72686529  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 29  
00000079    0.72703069  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 30  
00000080    0.72719038  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 31  
00000081    0.72735178  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 32  
00000082    0.72751099  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 33  
00000083    0.72766930  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 34  
00000084    0.72771364  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 35  
00000085    0.72790432  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 36  
00000086    0.72805601  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 37  
00000087    0.72822320  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 38  
00000088    0.72837883  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 39  
00000089    0.72853673  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 40  
00000090    0.72869104  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 41  
00000091    0.72884536  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 42  
00000092    0.72931057  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 43  
00000093    0.72961479  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 44  
00000094    0.72982675  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 45  
00000095    0.72999257  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 46  
00000096    0.73001790  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 47  
00000097    0.73019081  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 48  
00000098    0.73034960  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 49  
00000099    0.73050702  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 50  
00000100    0.73066491  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 51  
00000101    0.73082054  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 52  
00000102    0.73086667  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 53  
00000103    0.73095846  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 54  
00000104    0.73104805  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 55  
00000105    0.73120725  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 56  
00000106    0.73136157  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 57  
00000107    0.73151630  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 58  
00000108    0.73167068  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 59  
00000109    0.73182452  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 60  
00000110    0.73200679  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 61  
00000111    0.73212254  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 62  
00000112    0.73228043  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid UsbK handle reference count 1 at index 63  
00000113    0.73243207  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 0   
00000114    0.73258376  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 1   
00000115    0.73273587  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 2   
00000116    0.73288751  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 3   
00000117    0.73303831  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 4   
00000118    0.73319042  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 5   
00000119    0.73334163  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 6   
00000120    0.73338509  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 7   
00000121    0.73359436  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 8   
00000122    0.73375005  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 9   
00000123    0.73401123  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 10  
00000124    0.73413587  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 11  
00000125    0.73429239  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 12  
00000126    0.73444939  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 13  
00000127    0.73460591  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 14  
00000128    0.73476201  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 15  
00000129    0.73485428  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 16  
00000130    0.73487687  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 17  
00000131    0.73489815  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 18  
00000132    0.73501700  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 19  
00000133    0.73521435  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 20  
00000134    0.73540771  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 21  
00000135    0.73560590  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 22  
00000136    0.73580593  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 23  
00000137    0.73605335  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 24  
00000138    0.73629373  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 25  
00000139    0.73648971  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 26  
00000140    0.73664981  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 27  
00000141    0.73680860  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 28  
00000142    0.73698550  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 29  
00000143    0.73711413  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 30  
00000144    0.73733807  [1204] [WRN](libusbK.dll)[LibK_Context_Free] Invalid DevK handle reference count 2 at index 31  

@ghost
Copy link

ghost commented Dec 1, 2014

"If I install my Windows drivers as WinUSB and don't have libusbK in the path, I can open the device 50 times without any problems. With libusbK in the path, it fails after 32 tries"
Disadvantages

Only one application can access the device at a time
Doesn't support isochronous transfers (isochronous transfer mode will be made available with Windows 8.1)

quote from wikipedia http://en.m.wikipedia.org/wiki/WinUSB

rabryan pushed a commit to rabryan/libusb that referenced this issue Dec 10, 2014
* issue libusb#16 "Unable to claim interface multiple times"
* interface 0 is auto-claimed on windows when other
  interfaces are claimed, but it wasnt released along
  with the other interface
@rabryan
Copy link

rabryan commented Dec 16, 2014

If anyone needs a quick hack fix for this issue, you can use the commit here: rabryan@473e2ec

This issue stems from the fact that interface 0 is auto-claimed on windows when interfaces 1 and higher are claimed, but when those interfaces are explicitly released the auto-claimed interface 0 is not released. The commit above fixes this issue, but also introduces a bug whenever interface 0 and 1 are explicitly claimed but then the user only releases interface 1. In that case, interface 0 will be auto-released erroneously. So as long as that use case doesn't apply for you, the commit above will work fine.

rabryan pushed a commit to rabryan/libusb that referenced this issue Dec 19, 2014
* issue libusb#16 "Unable to claim interface multiple times"
* interface 0 is auto-claimed on windows when other
  interfaces are claimed, but it wasnt released along
  with the other interface
@dickens
Copy link
Member

dickens commented Jan 3, 2015

Hi,

Please try the patch below and see if that resolves the issue you are observing.

Regards,
Chris

From 4bb0fffcefc507f301afdfd97a40f17ecd839a25 Mon Sep 17 00:00:00 2001
From: Chris Dickens <christopher.a.dickens@gmail.com>
Date: Sat, 3 Jan 2015 01:07:07 -0800
Subject: [PATCH] Windows: Fix auto-claim functionality for WinUSB API

* Correctly auto-release interface 0 when releasing associated interface(s)
* Correctly handle when interface 0 is claimed after one or more associated
  interfaces so as to not release interface 0 prematurely
* Closes #16
---
 libusb/os/windows_usb.c | 170 +++++++++++++++++++++++++++++++++---------------
 libusb/os/windows_usb.h |   1 +
 2 files changed, 119 insertions(+), 52 deletions(-)

diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index a36ab45..fd8597e 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -2835,6 +2835,45 @@ static int winusbx_configure_endpoints(int sub_api, struct libusb_device_handle
    return LIBUSB_SUCCESS;
 }

+static int winusbx_autoclaim_iface0(int sub_api, struct libusb_device_handle *dev_handle)
+{
+   struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+   HANDLE file_handle, winusb_handle;
+
+   winusb_handle = handle_priv->interface_handle[0].api_handle;
+   if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) {
+       file_handle = handle_priv->interface_handle[0].dev_handle;
+       if ((file_handle == 0) || (file_handle == INVALID_HANDLE_VALUE)) {
+           return LIBUSB_ERROR_NOT_FOUND;
+       }
+
+       if (!WinUSBX[sub_api].Initialize(file_handle, &winusb_handle)) {
+           return LIBUSB_ERROR_ACCESS;
+       }
+       handle_priv->interface_handle[0].api_handle = winusb_handle;
+   }
+   handle_priv->iface0_claim_count++;
+
+   return LIBUSB_SUCCESS;
+}
+
+static void winusbx_autorelease_iface0(int sub_api, struct libusb_device_handle *dev_handle)
+{
+   struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+   HANDLE winusb_handle;
+
+   winusb_handle = handle_priv->interface_handle[0].api_handle;
+   if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) {
+       usbi_err(HANDLE_CTX(dev_handle), "program assertion failed: WinUSB handle is not present for interface 0");
+       return;
+   }
+
+   if (--handle_priv->iface0_claim_count == 0) {
+       WinUSBX[sub_api].Free(winusb_handle);
+       handle_priv->interface_handle[0].api_handle = INVALID_HANDLE_VALUE;
+   }
+}
+
 static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
 {
    struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
@@ -2843,7 +2882,7 @@ static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev
    bool is_using_usbccgp = (priv->apib->id == USB_API_COMPOSITE);
    HANDLE file_handle, winusb_handle;
    DWORD err;
-   int i;
+   int i, r;
    SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL;
    HDEVINFO dev_info = INVALID_HANDLE_VALUE;
    SP_DEVINFO_DATA dev_info_data;
@@ -2862,65 +2901,79 @@ static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev
            return LIBUSB_ERROR_NOT_FOUND;
        }

-       if (!WinUSBX[sub_api].Initialize(file_handle, &winusb_handle)) {
-           handle_priv->interface_handle[iface].api_handle = INVALID_HANDLE_VALUE;
-           err = GetLastError();
-           switch(err) {
-           case ERROR_BAD_COMMAND:
-               // The device was disconnected
-               usbi_err(ctx, "could not access interface %d: %s", iface, windows_error_str(0));
-               return LIBUSB_ERROR_NO_DEVICE;
-           default:
-               // it may be that we're using the libusb0 filter driver.
-               // TODO: can we move this whole business into the K/0 DLL?
-               for (i = 0; ; i++) {
-                   safe_free(dev_interface_details);
-                   safe_free(dev_path_no_guid);
-                   dev_interface_details = get_interface_details_filter(ctx, &dev_info, &dev_info_data, &GUID_DEVINTERFACE_LIBUSB0_FILTER, i, filter_path);
-                   if ((found_filter) || (dev_interface_details == NULL)) {
-                       break;
-                   }
-                   // ignore GUID part
-                   dev_path_no_guid = sanitize_path(strtok(dev_interface_details->DevicePath, "{"));
-                   if (safe_strncmp(dev_path_no_guid, priv->usb_interface[iface].path, safe_strlen(dev_path_no_guid)) == 0) {
-                       file_handle = CreateFileA(filter_path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ,
-                           NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
-                       if (file_handle == INVALID_HANDLE_VALUE) {
-                           usbi_err(ctx, "could not open device %s: %s", filter_path, windows_error_str(0));
-                       } else {
-                           WinUSBX[sub_api].Free(winusb_handle);
-                           if (WinUSBX[sub_api].Initialize(file_handle, &winusb_handle))
-                               found_filter = true;
-                           else
-                               usbi_err(ctx, "could not initialize filter driver for %s", filter_path);
+       winusb_handle = handle_priv->interface_handle[iface].api_handle;
+       if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) {
+           if (!WinUSBX[sub_api].Initialize(file_handle, &winusb_handle)) {
+               handle_priv->interface_handle[iface].api_handle = INVALID_HANDLE_VALUE;
+               err = GetLastError();
+               switch(err) {
+               case ERROR_BAD_COMMAND:
+                   // The device was disconnected
+                   usbi_err(ctx, "could not access interface %d: %s", iface, windows_error_str(0));
+                   return LIBUSB_ERROR_NO_DEVICE;
+               default:
+                   // it may be that we're using the libusb0 filter driver.
+                   // TODO: can we move this whole business into the K/0 DLL?
+                   for (i = 0; ; i++) {
+                       safe_free(dev_interface_details);
+                       safe_free(dev_path_no_guid);
+                       dev_interface_details = get_interface_details_filter(ctx, &dev_info, &dev_info_data, &GUID_DEVINTERFACE_LIBUSB0_FILTER, i, filter_path);
+                       if ((found_filter) || (dev_interface_details == NULL)) {
+                           safe_free(dev_interface_details);
+                           break;
+                       }
+                       // ignore GUID part
+                       dev_path_no_guid = sanitize_path(strtok(dev_interface_details->DevicePath, "{"));
+                       if (safe_strncmp(dev_path_no_guid, priv->usb_interface[iface].path, safe_strlen(dev_path_no_guid)) == 0) {
+                           file_handle = CreateFileA(filter_path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ,
+                               NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+                           if (file_handle == INVALID_HANDLE_VALUE) {
+                               usbi_err(ctx, "could not open device %s: %s", filter_path, windows_error_str(0));
+                           } else {
+                               WinUSBX[sub_api].Free(winusb_handle);
+                               if (WinUSBX[sub_api].Initialize(file_handle, &winusb_handle))
+                                   found_filter = true;
+                               else
+                                   usbi_err(ctx, "could not initialize filter driver for %s", filter_path);
+                           }
                        }
                    }
+                   if (!found_filter) {
+                       usbi_err(ctx, "could not access interface %d: %s", iface, windows_error_str(err));
+                       return LIBUSB_ERROR_ACCESS;
+                   }
                }
-               if (!found_filter) {
-                   usbi_err(ctx, "could not access interface %d: %s", iface, windows_error_str(err));
-                   return LIBUSB_ERROR_ACCESS;
-               }
            }
+           handle_priv->interface_handle[iface].api_handle = winusb_handle;
+       }
+       else {
+           if (is_using_usbccgp) {
+               usbi_err(ctx, "program assertion failed: composite device already has WinUSB handle for interface %d", iface);
+               return LIBUSB_ERROR_OTHER;
+           }
+
+           usbi_dbg("explicitly claiming previously auto-claimed interface 0");
+       }
+
+       if ((!is_using_usbccgp) && (iface == 0)) {
+           handle_priv->iface0_claim_count++;
        }
-       handle_priv->interface_handle[iface].api_handle = winusb_handle;
    } else {
        // For all other interfaces, use GetAssociatedInterface()
-       winusb_handle = handle_priv->interface_handle[0].api_handle;
+
        // It is a requirement for multiple interface devices on Windows that, to you
        // must first claim the first interface before you claim the others
-       if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) {
-           file_handle = handle_priv->interface_handle[0].dev_handle;
-           if (WinUSBX[sub_api].Initialize(file_handle, &winusb_handle)) {
-               handle_priv->interface_handle[0].api_handle = winusb_handle;
-               usbi_warn(ctx, "auto-claimed interface 0 (required to claim %d with WinUSB)", iface);
-           } else {
-               usbi_warn(ctx, "failed to auto-claim interface 0 (required to claim %d with WinUSB): %s", iface, windows_error_str(0));
-               return LIBUSB_ERROR_ACCESS;
-           }
+       r = winusbx_autoclaim_iface0(sub_api, dev_handle);
+       if (r != LIBUSB_SUCCESS) {
+           usbi_warn(ctx, "failed to auto-claim interface 0 (required to claim %d with WinUSB): %s", iface, windows_error_str(0));
+           return r;
        }
+       usbi_warn(ctx, "auto-claimed interface 0 (required to claim %d with WinUSB)", iface);
+       winusb_handle = handle_priv->interface_handle[0].api_handle;
        if (!WinUSBX[sub_api].GetAssociatedInterface(winusb_handle, (UCHAR)(iface-1),
            &handle_priv->interface_handle[iface].api_handle)) {
            handle_priv->interface_handle[iface].api_handle = INVALID_HANDLE_VALUE;
+           winusbx_autorelease_iface0(sub_api, dev_handle);
            switch(GetLastError()) {
            case ERROR_NO_MORE_ITEMS:   // invalid iface
                return LIBUSB_ERROR_NOT_FOUND;
@@ -2942,19 +2995,32 @@ static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev

 static int winusbx_release_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
 {
+   struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
    struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
    struct windows_device_priv *priv = _device_priv(dev_handle->dev);
    HANDLE winusb_handle;
+   bool is_using_usbccgp = (priv->apib->id == USB_API_COMPOSITE);

    CHECK_WINUSBX_AVAILABLE(sub_api);

-   winusb_handle = handle_priv->interface_handle[iface].api_handle;
-   if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) {
-       return LIBUSB_ERROR_NOT_FOUND;
+   if ((is_using_usbccgp) || (iface != 0)) {
+       winusb_handle = handle_priv->interface_handle[iface].api_handle;
+       if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) {
+           return LIBUSB_ERROR_NOT_FOUND;
+       }
+
+       WinUSBX[sub_api].Free(winusb_handle);
+       handle_priv->interface_handle[iface].api_handle = INVALID_HANDLE_VALUE;
    }

-   WinUSBX[sub_api].Free(winusb_handle);
-   handle_priv->interface_handle[iface].api_handle = INVALID_HANDLE_VALUE;
+   if (!is_using_usbccgp) {
+       // Need to auto-release interface 0 for non-composite devices
+       // Note that this is how interface 0 is finally released for such devices
+       winusbx_autorelease_iface0(sub_api, dev_handle);
+       if (iface != 0) {
+           usbi_warn(ctx, "auto-released interface 0 (required to claim %d with WinUSB)", iface);
+       }
+   }

    return LIBUSB_SUCCESS;
 }
diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h
index 817a469..fa229b9 100644
--- a/libusb/os/windows_usb.h
+++ b/libusb/os/windows_usb.h
@@ -284,6 +284,7 @@ struct windows_device_handle_priv {
    int active_interface;
    struct interface_handle_t interface_handle[USB_MAXINTERFACES];
    int autoclaim_count[USB_MAXINTERFACES]; // For auto-release
+   int iface0_claim_count;
 };

 static inline struct windows_device_handle_priv *_device_handle_priv(
-- 
1.9.3


@mcuee
Copy link
Member

mcuee commented Jan 10, 2015

Hi Chris,

I want to test out this patch but it does not seem to apply to current git
master.

Could you please generate a new patch? Thanks.

Regards,
Xiaofan

@dickens
Copy link
Member

dickens commented Jan 10, 2015

Hmm, it appears that it doesn't apply cleanly because the whitespace is all messed up.

Please access the patch file from here: https://drive.google.com/file/d/0B21dl58QIZY-NGpLWExOSEhHdDg/view

Regards,
Chris

@mcuee
Copy link
Member

mcuee commented Jan 10, 2015

Thanks. Now the patch applies cleanly on top of git master. However, it
does not help. That is to say the issue is still there when libusbK.dll is
present.

Xiaofan

@dickens
Copy link
Member

dickens commented Jan 11, 2015

This problem may be an bug in libusbK. Apparently, simply closing the device handle (the one from CreateFile) is not sufficient as libusbK does not release resources properly.

@mcuee
Copy link
Member

mcuee commented Jan 11, 2015

On Sun, Jan 11, 2015 at 3:56 PM, Chris Dickens notifications@github.com
wrote:

Closed #16 #16 via 63a440f
63a440f
.


Reply to this email directly or view it on GitHub
#16 (comment).

Hi Chris,

The patch seems to break the build since "handle" is not defined, probably
it should
be file_handle. Please check in a new fix.

Xiaofan

@mcuee
Copy link
Member

mcuee commented Jan 11, 2015

On Sun, Jan 11, 2015 at 4:02 PM, Chris Dickens notifications@github.com
wrote:

This problem may be an bug in libusbK. Apparently, simply closing the
device handle (the one from CreateFile) is not sufficient as libusbK does
not release resources properly.


Reply to this email directly or view it on GitHub
#16 (comment).

Thanks. I will relay this message to Travis.

And yes your patch indeed fixed the problem after I fixed the build issue.
Thanks.

Xiaofan

@mcuee
Copy link
Member

mcuee commented Jan 11, 2015

Sorry about that...too much concurrent development. Fix has been applied.

Regards,
Chris

On Sun, Jan 11, 2015 at 2:14 AM, Xiaofan Chen xiaofanc@gmail.com wrote:

On Sun, Jan 11, 2015 at 3:56 PM, Chris Dickens notifications@github.com
wrote:

Closed #16 #16 via 63a440f
63a440f
.


Reply to this email directly or view it on GitHub
#16 (comment).

Hi Chris,

The patch seems to break the build since "handle" is not defined, probably
it should
be file_handle. Please check in a new fix.

Xiaofan

philb pushed a commit to openembedded/openembedded-core that referenced this issue Nov 25, 2015
This updates libusb1 from 1.0.19 to 1.0.20

2015-09-13: v1.0.20
* Add Haiku support
* Fix multiple memory and resource leaks (#16, #52, #76, #81)
* Fix possible deadlock when executing transfer callback
* New libusb_free_pollfds() API
* Darwin: Fix devices not being detected on OS X 10.8 (#48)
* Linux: Allow larger isochronous transfer submission (#23)
* Windows: Fix broken builds Cygwin/MinGW builds and compiler warnings
* Windows: Fix broken bus number lookup
* Windows: Improve submission of control requests for composite devices
* Examples: Add two-stage load support to fxload (#12)
* Correctly report cancellations due to timeouts
* Improve efficiency of event handling
* Improve speed of transfer submission in multi-threaded environments
* Various other bug fixes and improvements
The (#xx) numbers are libusb issue numbers, see ie:
libusb/libusb#16

Signed-off-by: Jens Rehsack <sno@netbsd.org>
Signed-off-by: Ross Burton <ross.burton@intel.com>
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Apr 9, 2016
add experimental SunOS backend support adapted from the upstream RTI
submission from Oracle and initial illumos support from OpenIndiana/Hipster

From the Changelog:
For detailed information about the changes below, please see the git log or
visit: http://log.libusb.info

2015-09-13: v1.0.20
* Add Haiku support
* Fix multiple memory and resource leaks (#16, #52, #76, #81)
* Fix possible deadlock when executing transfer callback
* New libusb_free_pollfds() API
* Darwin: Fix devices not being detected on OS X 10.8 (#48)
* Linux: Allow larger isochronous transfer submission (#23)
* Windows: Fix broken builds Cygwin/MinGW builds and compiler warnings
* Windows: Fix broken bus number lookup
* Windows: Improve submission of control requests for composite devices
* Examples: Add two-stage load support to fxload (#12)
* Correctly report cancellations due to timeouts
* Improve efficiency of event handling
* Improve speed of transfer submission in multi-threaded environments
* Various other bug fixes and improvements
The (#xx) numbers are libusb issue numbers, see ie:
libusb/libusb#16

MAKE_JOBS_SAFE=no given build issues when enabled.
Seneral pushed a commit to Seneral/libusb that referenced this issue Sep 21, 2021
* libusbK (as of v3.0.7.0) will fail after 32 opens because
  resources from claimed interfaces are not freed by simply
  closing just the device handle
* Closes libusb#16

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
@mcuee mcuee added the windows label Feb 16, 2024
daregit pushed a commit to daregit/yocto-combined that referenced this issue May 22, 2024
This updates libusb1 from 1.0.19 to 1.0.20

2015-09-13: v1.0.20
* Add Haiku support
* Fix multiple memory and resource leaks (#16, #52, #76, #81)
* Fix possible deadlock when executing transfer callback
* New libusb_free_pollfds() API
* Darwin: Fix devices not being detected on OS X 10.8 (#48)
* Linux: Allow larger isochronous transfer submission (#23)
* Windows: Fix broken builds Cygwin/MinGW builds and compiler warnings
* Windows: Fix broken bus number lookup
* Windows: Improve submission of control requests for composite devices
* Examples: Add two-stage load support to fxload (#12)
* Correctly report cancellations due to timeouts
* Improve efficiency of event handling
* Improve speed of transfer submission in multi-threaded environments
* Various other bug fixes and improvements
The (#xx) numbers are libusb issue numbers, see ie:
libusb/libusb#16

(From OE-Core rev: 641a9454fbb25f1458bb8f96cbfada3e0da98dee)

Signed-off-by: Jens Rehsack <sno@netbsd.org>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants