Fix iOS crash issues

Relate to issues #327 and #63.
mosq->sock may be closed before FD_SET(mosq->sock, &writefds) and
FD_ISSET(mosq->sock, &writefds) but after judgement in line 947
if(mosq->sock != INVALID_SOCKET). FD_SET(-1, ...) and FD_ISSET(-1, ...)
would certainly crash.

Signed-off-by: Zard1096 <mr.zardqi@gmail.com>
This commit is contained in:
Zard1096 2017-07-11 13:08:38 +08:00 committed by Roger A. Light
parent 0ba0bc434e
commit 5b73897f98

View File

@ -971,9 +971,10 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
/* Fake write possible, to stimulate output write even though /* Fake write possible, to stimulate output write even though
* we didn't ask for it, because at that point the publish or * we didn't ask for it, because at that point the publish or
* other command wasn't present. */ * other command wasn't present. */
if(mosq->sock != INVALID_SOCKET)
FD_SET(mosq->sock, &writefds); FD_SET(mosq->sock, &writefds);
} }
if(FD_ISSET(mosq->sock, &writefds)){ if(mosq->sock != INVALID_SOCKET && FD_ISSET(mosq->sock, &writefds)){
#ifdef WITH_TLS #ifdef WITH_TLS
if(mosq->want_connect){ if(mosq->want_connect){
rc = mosquitto__socket_connect_tls(mosq); rc = mosquitto__socket_connect_tls(mosq);