diff --git a/src/conf.c b/src/conf.c index 122404c2..15d62038 100644 --- a/src/conf.c +++ b/src/conf.c @@ -235,6 +235,9 @@ void mqtt3_config_cleanup(struct mqtt3_config *config) if(config->listeners[i].crlfile) _mosquitto_free(config->listeners[i].crlfile); if(config->listeners[i].tls_version) _mosquitto_free(config->listeners[i].tls_version); if(config->listeners[i].ssl_ctx) SSL_CTX_free(config->listeners[i].ssl_ctx); +#endif +#ifdef WITH_WEBSOCKETS + if(config->listeners[i].http_dir) _mosquitto_free(config->listeners[i].http_dir); #endif } _mosquitto_free(config->listeners); diff --git a/src/mosquitto.c b/src/mosquitto.c index 4be46938..0f74fdb9 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -342,6 +342,32 @@ int main(int argc, char *argv[]) } #endif +#ifdef WITH_WEBSOCKETS + for(i=0; ilistener_count; i++){ + if(int_db.config->listeners[i].ws_context){ + hack_head = libwebsocket_context_user(int_db.config->listeners[i].ws_context); + libwebsocket_context_destroy(int_db.config->listeners[i].ws_context); + if(hack_head){ + while(hack_head){ +#ifdef WIN32 +#error FIXME +#else + if(hack_head->http_dir){ + _mosquitto_free(hack_head->http_dir); + } +#endif + hack = hack_head->next; + _mosquitto_free(hack_head); + hack_head = hack; + } + } + } + if(int_db.config->listeners[i].ws_protocol){ + _mosquitto_free(int_db.config->listeners[i].ws_protocol); + } + } +#endif + HASH_ITER(hh_id, int_db.contexts_by_id, ctxt, ctxt_tmp){ #ifdef WITH_WEBSOCKETS if(!ctxt->wsi){ @@ -363,21 +389,6 @@ int main(int argc, char *argv[]) HASH_DELETE(hh_for_free, int_db.contexts_for_free, ctxt); mqtt3_context_cleanup(&int_db, ctxt, true); } -#ifdef WITH_WEBSOCKETS - for(i=0; ilistener_count; i++){ - if(int_db.config->listeners[i].ws_context){ - hack_head = libwebsocket_context_user(int_db.config->listeners[i].ws_context); - libwebsocket_context_destroy(int_db.config->listeners[i].ws_context); - if(hack_head){ - while(hack_head){ - hack = hack_head->next; - _mosquitto_free(hack_head); - hack_head = hack; - } - } - } - } -#endif mqtt3_db_close(&int_db); diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index 2a210ce4..1c4c40a6 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -76,6 +76,7 @@ struct _mqtt3_listener { #ifdef WITH_WEBSOCKETS struct libwebsocket_context *ws_context; char *http_dir; + struct libwebsocket_protocols *ws_protocol; #endif }; diff --git a/src/websockets.c b/src/websockets.c index 63123b11..e256a856 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -513,6 +513,7 @@ struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listen #endif user = _mosquitto_calloc(1, sizeof(struct libws_mqtt_hack)); if(!user){ + _mosquitto_free(p); return NULL; } @@ -523,11 +524,13 @@ struct libwebsocket_context *mosq_websockets_init(struct _mqtt3_listener *listen user->http_dir = realpath(listener->http_dir, NULL); if(!user->http_dir){ _mosquitto_free(user); + _mosquitto_free(p); return NULL; } } #endif info.user = user; + listener->ws_protocol = p; lws_set_log_level(0, NULL);