WinCE: Fix device reference leak which caused crash on libusb_exit().

The Windows CE device allocation code has always had a bug where it would
leak references to devices when they are allocated. This commit removes the
reference leak.

This leak was highlighted by the new hotplug code which now triggers a NULL
pointer dereference if not all devices are unreferenced before libusb_exit
is called.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
WinCE: ref result of usbi_get_device_by_session_id()

After the "WinCE: Fix device reference leak which caused crash on
libusb_exit()" commit, the code always unref-s dev after adding it to
discovered_devs. But if dev comes from usbi_get_device_by_session_id()
it is a weak ref and as such should not be unreffed.

Instead of re-adding comlicate ref tracking logic, this patch fixes this with
a libusb_device_ref(dev) of dev comes from usbi_get_device_by_session_id(),
turning the weak ref into a strong ref.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
core: Only do hotplug cleanup for hotplug capable backends

Xiaofan encountered a crash while testing on openbsd. The main problem here is
libusb_exit doing hotplug cleanup on a non hotplug capable backend.

If the usb_devs list is non empty (*) at libusb_exit time with a non hotplug
capable backend, then the hotplug cleanup code will unref the devices
in the list. Assuming this is the last unref, then libusb_unref_device
will call usbi_disconnect_device, which will try to take the usb_devs_lock,
which is already hold by libusb_exit. Note that if this deadlock was not
there, that we then also would have a double list_del issue.

*) This should never happen, if it does either libusb or the app has a memleak,
or the app still holds a reference to the device. The latter is an application
bug, since device->ctx will be invalid after libusb_exit, so the application
should not hold references after calling libusb_exit.

In this case we have a memleak the libusb openbsd code causing the usb_devs
list to be non empty. This will be fixed in another commit.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
openbsd: Fix memleak in obsd_get_device_list()

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
core.c: Initialize auto_detach_kernel_driver to 0 for new handle

Signed-off-by: Hans de Goede <hdegoede@redhat.com>