Hi, this isnt a full review but i have a note:
libusb_set_debug(NULL, 3); // Enable information, warning and error messages (only).
libusb_set_debug(NULL, 4); // Enable information, warning and error messages (only).
Was this supposed to be a part of this patch? ;)