Closes #150

Signed-off-by: Hans de Goede <hdego...@redhat.com>
---
 libusb/core.c         | 14 ++++++++++++++
 libusb/version_nano.h |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/libusb/core.c b/libusb/core.c
index ea6adcb..b472e89 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -1969,6 +1969,7 @@ err_unlock:
 void API_EXPORTED libusb_exit(struct libusb_context *ctx)
 {
        struct libusb_device *dev, *next;
+       struct timeval tv = { 0, };
 
        usbi_dbg("");
        USBI_GET_CONTEXT(ctx);
@@ -1993,6 +1994,19 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx)
 
        if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
                usbi_hotplug_deregister_all(ctx);
+
+               /*
+                * Ensure any pending unplug events are read from the hotplug
+                * pipe. The usb_device-s hold in the events are no longer part
+                * of usb_devs, but the events still hold a reference!
+                *
+                * Note we don't do this if the application has left devices
+                * open (which implies a buggy app) to avoid packet completion
+                * handlers running when the app does not expect them to run.
+                */
+               if (list_empty(&ctx->open_devs))
+                       libusb_handle_events_timeout(ctx, &tv);
+
                usbi_mutex_lock(&ctx->usb_devs_lock);
                list_for_each_entry_safe(dev, next, &ctx->usb_devs, list, 
struct libusb_device) {
                        list_del(&dev->list);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index d30ecec..a833d52 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10838
+#define LIBUSB_NANO 10839
-- 
1.8.3.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to