Add mosquitto_loop_stop before mosquitto_destroy in close()

The background network thread started by mosquitto_loop_start() was not
being stopped before mosquitto_destroy(), which can cause a use-after-free
if the thread is still running when the mosquitto structure is freed.
This commit is contained in:
Andy Taylor 2026-03-08 14:16:34 +00:00
parent 8efcac05e6
commit 469306ff1f

View file

@ -147,6 +147,7 @@ void CMQTTConnection::close()
{
if (m_mosq != nullptr) {
::mosquitto_disconnect(m_mosq);
::mosquitto_loop_stop(m_mosq, true);
::mosquitto_destroy(m_mosq);
m_mosq = nullptr;
}