1
0
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:
Frank Pagliughi 2025-01-03 16:29:27 -05:00 committed by GitHub
commit 461f765430
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}