1
0
mirror of https://github.com/eclipse/paho.mqtt.cpp.git synced 2025-05-09 11:21:24 +08:00

Fix potential deadlock in set_callback

Signed-off-by: Sandro Scherer <sand.scherer@gmail.com>
This commit is contained in:
Sandro Scherer 2024-10-08 09:51:20 +02:00
parent 6131a30530
commit 5956f3b112

View File

@ -315,9 +315,10 @@ void async_client::remove_token(token* tok)
void async_client::set_callback(callback& cb)
{
guard g(lock_);
userCallback_ = &cb;
{
guard g(lock_);
userCallback_ = &cb;
}
int rc = MQTTAsync_setConnected(cli_, this, &async_client::on_connected);
if (rc == MQTTASYNC_SUCCESS) {
@ -330,6 +331,7 @@ void async_client::set_callback(callback& cb)
MQTTAsync_setConnected(cli_, nullptr, nullptr);
if (rc != MQTTASYNC_SUCCESS) {
guard g(lock_);
userCallback_ = nullptr;
throw exception(rc);
}