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:32 +00:00
parent 50a3567335
commit 139d9dbff5

View file

@ -146,6 +146,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;
}