From: Uwe Hermann Date: Sun, 12 Apr 2015 14:34:26 +0000 (+0200) Subject: Fix a USB timeout related issue in sr_session_iteration(). X-Git-Tag: libsigrok-0.4.0~533 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1190c65397e8246bd3b437006bacc5b7dc9d2bde;p=libsigrok.git Fix a USB timeout related issue in sr_session_iteration(). This issue could lead to e.g. crashes when an OLS was used. This fixes bug #571. --- diff --git a/src/session.c b/src/session.c index 0780a27a..a3f6a86d 100644 --- a/src/session.c +++ b/src/session.c @@ -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