diff --git a/ChangeLog.txt b/ChangeLog.txt index d7cdf92c..45fbd33d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,7 @@ Broker: Client library: - Clients can now use TLS with IPv6. - Fix potential socket leakage when reconnecting. Closes #304. +- Fix potential negative timeout being passed to pselect. Closes #329. 1.4.10 - 20160816 diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 732e18f3..afd7e375 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -916,6 +916,12 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets) timeout = (mosq->next_msg_out - now)*1000; } + if(timeout < 0){ + /* There has been a delay somewhere which means we should have already + * sent a message. */ + timeout = 0; + } + local_timeout.tv_sec = timeout/1000; #ifdef HAVE_PSELECT local_timeout.tv_nsec = (timeout-local_timeout.tv_sec*1000)*1e6;