From c02cdbefdc82dc36ed0a042c1e49cde359754e7f Mon Sep 17 00:00:00 2001 From: Simon Wunderlich Date: Wed, 4 Feb 2015 19:38:30 +0100 Subject: [PATCH] mosquitto-lib: close socketpair on (re)connect If the socket pair is still opened on reconnect, close it before creating it again (just like the state variables). Otherwise, these sockets are leaked on multiple mosquitto_connect() calls. Signed-off-by: Simon Wunderlich --- lib/mosquitto.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 50ba9eb6..195a25aa 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -407,6 +407,15 @@ static int _mosquitto_connect_init(struct mosquitto *mosq, const char *host, int mosq->keepalive = keepalive; + if(mosq->sockpairR != INVALID_SOCKET){ + COMPAT_CLOSE(mosq->sockpairR); + mosq->sockpairR = INVALID_SOCKET; + } + if(mosq->sockpairW != INVALID_SOCKET){ + COMPAT_CLOSE(mosq->sockpairW); + mosq->sockpairW = INVALID_SOCKET; + } + if(_mosquitto_socketpair(&mosq->sockpairR, &mosq->sockpairW)){ _mosquitto_log_printf(mosq, MOSQ_LOG_WARNING, "Warning: Unable to open socket pair, outgoing publish commands may be delayed.");