mirror of
https://github.com/eclipse/paho.mqtt.cpp.git
synced 2025-05-09 19:31:22 +08:00
Merge pull request #519 from sandro97git/set-callback-fix-potential-deadlock
Fix potential deadlock in set_callback
This commit is contained in:
commit
461f765430
@ -314,10 +314,11 @@ void async_client::remove_token(token* tok)
|
||||
// Callback management
|
||||
|
||||
void async_client::set_callback(callback& 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user