Skip to content

libusb logs libusb: warning [libusb_exit] device 2.0 still referenced on app exit #62

Open
@diablodale

Description

@diablodale

usbLinkOpen() in the develop branch calls libusb_ref_device() to increment the ref, but I can not find any code that will decrement it using libusb_unref_device().

This is suspicious and may have unwanted sideaffects. libusb doc writes that ref/unref need to be matched and when ref=0 a device is finally destroyed.

libusb_ref_device() only exists one place...it is within refLibusbDeviceByName()

libusb_ref_device(devs[i]);

That function above refLibusbDeviceByName() is called by code in three locations...

usb_boot() location

Looks correct to me. It has a matching unref.

if(refLibusbDeviceByName(addr, &dev) == X_LINK_PLATFORM_SUCCESS){
break;
}
std::this_thread::sleep_for(milliseconds(10));
} while(steady_clock::now() - t1 < DEFAULT_CONNECT_TIMEOUT);
if(dev == nullptr) {
return X_LINK_PLATFORM_DEVICE_NOT_FOUND;
}
auto t2 = steady_clock::now();
do {
if((res = usb_open_device(dev, &endpoint, h)) == LIBUSB_SUCCESS){
break;
}
std::this_thread::sleep_for(milliseconds(100));
} while(steady_clock::now() - t2 < DEFAULT_CONNECT_TIMEOUT);
if(res == LIBUSB_SUCCESS) {
rc = send_file(h, endpoint, mvcmd, size, bcdusb);
libusb_release_interface(h, 0);
libusb_close(h);
} else {
if(res == LIBUSB_ERROR_ACCESS) {
rc = X_LINK_PLATFORM_INSUFFICIENT_PERMISSIONS;
} else if(res == LIBUSB_ERROR_BUSY) {
rc = X_LINK_PLATFORM_DEVICE_BUSY;
} else {
rc = X_LINK_PLATFORM_ERROR;
}
}
if (dev) {
libusb_unref_device(dev);

usbLinkBootBootloader() location

Looks correct to me. It has a matching unref.

auto refErr = refLibusbDeviceByName(path, &dev);

usbLinkOpen location

Looks suspicious. It calls refLibusbDeviceByName which increments the ref. But nothing calls unref. If I guess, I would think there should be an unref in usbLinkClose but there is not.

if(refLibusbDeviceByName(path, &dev) == X_LINK_PLATFORM_SUCCESS){

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions