Skip to content

Commit

Permalink
Add mutex protection to MqttClient_NetDisconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
embhorn committed Jul 19, 2023
1 parent 2c95cb5 commit edae099
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,26 @@ int MqttClient_NetConnect(MqttClient *client, const char* host,

int MqttClient_NetDisconnect(MqttClient *client)
{
#ifdef WOLFMQTT_MULTITHREAD
MqttPendResp *tmpResp;
#endif

if (client == NULL) {
return MQTT_CODE_ERROR_BAD_ARG;
}

#ifdef WOLFMQTT_MULTITHREAD
/* Get client lock on to ensure no other threads are active */
wm_SemLock(&client->lockClient);

for (tmpResp = client->firstPendResp;
tmpResp != NULL;
tmpResp = tmpResp->next) {
MqttClient_RespList_Remove(client, tmpResp);
}
wm_SemUnlock(&client->lockClient);
#endif

return MqttSocket_Disconnect(client);
}

Expand Down

0 comments on commit edae099

Please sign in to comment.