diff --git a/ChangeLog.txt b/ChangeLog.txt index e31fbbb3..27d3c73d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,12 @@ Clients: and mosquitto_rr, to avoid potentially lost messages. Closes #2134. - Fix TLS-PSK mode not working with port 8883. Closes #2152. +Client library: +- Fix possible socket leak. This would occur if a client was using + `mosquitto_loop_start()`, then if the connection failed due to the remote + server being inaccessible they called `mosquitto_loop_stop(, true)` and + recreated the mosquitto object. + Build: - A variety of minor build related fixes, like functions not having previous declarations. diff --git a/lib/net_mosq.c b/lib/net_mosq.c index d42d83a7..16d0e8c9 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -917,16 +917,13 @@ int net__socket_connect_step3(struct mosquitto *mosq, const char *host) /* Create a socket and connect it to 'ip' on port 'port'. */ int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) { - mosq_sock_t sock = INVALID_SOCKET; int rc, rc2; if(!mosq || !host) return MOSQ_ERR_INVAL; - rc = net__try_connect(host, port, &sock, bind_address, blocking); + rc = net__try_connect(host, port, &mosq->sock, bind_address, blocking); if(rc > 0) return rc; - mosq->sock = sock; - if(mosq->tcp_nodelay){ int flag = 1; if(setsockopt(mosq->sock, IPPROTO_TCP, TCP_NODELAY, (const void*)&flag, sizeof(int)) != 0){