diff --git a/ChangeLog.txt b/ChangeLog.txt index 0110aede..152e634f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,8 @@ Broker: - Fix memory leak if a client provided a username/password for a listener with use_identity_as_username configured. - Fix use_identity_as_username not working on websockets clients. +- Don't crash if an auth plugin returns MOSQ_ERR_AUTH for a username check on + a websockets client. Closes #490. Client library: - Fix incorrect PSK key being used if it had leading zeroes. diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 063c4a22..c51749c3 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -214,14 +214,19 @@ int _mosquitto_socket_close(struct mosquitto *mosq) assert(mosq); #ifdef WITH_TLS - if(mosq->ssl){ - SSL_shutdown(mosq->ssl); - SSL_free(mosq->ssl); - mosq->ssl = NULL; - } - if(mosq->ssl_ctx){ - SSL_CTX_free(mosq->ssl_ctx); - mosq->ssl_ctx = NULL; +#ifdef WITH_WEBSOCKETS + if(!mosq->wsi) +#endif + { + if(mosq->ssl){ + SSL_shutdown(mosq->ssl); + SSL_free(mosq->ssl); + mosq->ssl = NULL; + } + if(mosq->ssl_ctx){ + SSL_CTX_free(mosq->ssl_ctx); + mosq->ssl_ctx = NULL; + } } #endif