Skip to content

Commit

Permalink
Merge pull request #342 from embhorn/zd16343
Browse files Browse the repository at this point in the history
Add mutex protection to MqttClient_NetDisconnect
  • Loading branch information
lealem47 authored Jul 19, 2023
2 parents 43a9cc3 + edae099 commit 65a88f9
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 65a88f9

Please sign in to comment.