paho.mqtt.c icon indicating copy to clipboard operation
paho.mqtt.c copied to clipboard

Memory conflict between disconnect internal and destroy context by user

Open ElementOxygenWady opened this issue 5 years ago • 2 comments

Hello, I am Wady, your big fans. I find a BUG (please confirm). Create a thread in 'MQTTClient_disconnect_internal()' to notify connection lost and it will reference MQTTClients object. However this object call be freed in 'MQTTClient_destroy()'. I believe this is dangerous.

ElementOxygenWady avatar Jan 22 '20 00:01 ElementOxygenWady

MQTTClient_destroy() cleans up all the resources associated with a client object. It should only be called when the client is completely and properly disconnected so that those resources are not used any more.

icraggs avatar Jan 23 '20 12:01 icraggs

You are perfectly right and reasonable. But for 'MQTTClient_destroy ()', it is not known whether the thread created by 'MQTTClient_disconnect_internal ()' exists, the thread is detach. I think you can check 'MQTTClient_disconnect1()'. Create a thread in the function using 'Thread_start ()'.

ElementOxygenWady avatar Jan 23 '20 13:01 ElementOxygenWady