]> sigrok.org Git - libsigrok.git/commitdiff
Fix a USB timeout related issue in sr_session_iteration().
authorUwe Hermann <redacted>
Sun, 12 Apr 2015 14:34:26 +0000 (16:34 +0200)
committerUwe Hermann <redacted>
Sun, 12 Apr 2015 15:16:32 +0000 (17:16 +0200)
This issue could lead to e.g. crashes when an OLS was used.

This fixes bug #571.

src/session.c

index 0780a27ab3d2476e80df9e5af32ad184eb3bd9b4..a3f6a86d3ef8226659f67f5fc222ed44726bf14c 100644 (file)
@@ -385,17 +385,20 @@ static int sr_session_iteration(struct sr_session *session, gboolean block)
        struct timeval tv;
 #endif
 
-       timeout = block ? 0 : session->source_timeout;
+       timeout = block ? session->source_timeout : 0;
 
 #ifdef HAVE_LIBUSB_1_0
-       ret = libusb_get_next_timeout(session->ctx->libusb_ctx, &tv);
-       if (ret < 0) {
-               sr_err("Error getting libusb timeout: %s",
-                       libusb_error_name(ret));
-               return SR_ERR;
-       } else if (ret == 1) {
-               usb_timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000;
-               timeout = MIN(timeout, usb_timeout);
+       if (session->ctx->usb_source_present) {
+               timeout = block ? 0 : session->source_timeout;
+               ret = libusb_get_next_timeout(session->ctx->libusb_ctx, &tv);
+               if (ret < 0) {
+                       sr_err("Error getting libusb timeout: %s",
+                               libusb_error_name(ret));
+                       return SR_ERR;
+               } else if (ret == 1) {
+                       usb_timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+                       timeout = MIN(timeout, usb_timeout);
+               }
        }
 #endif