Skip to content

Commit 65a88f9

Browse files
authored
Merge pull request #342 from embhorn/zd16343
Add mutex protection to MqttClient_NetDisconnect
2 parents 43a9cc3 + edae099 commit 65a88f9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/mqtt_client.c

+20
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,26 @@ int MqttClient_NetConnect(MqttClient *client, const char* host,
26092609

26102610
int MqttClient_NetDisconnect(MqttClient *client)
26112611
{
2612+
#ifdef WOLFMQTT_MULTITHREAD
2613+
MqttPendResp *tmpResp;
2614+
#endif
2615+
2616+
if (client == NULL) {
2617+
return MQTT_CODE_ERROR_BAD_ARG;
2618+
}
2619+
2620+
#ifdef WOLFMQTT_MULTITHREAD
2621+
/* Get client lock on to ensure no other threads are active */
2622+
wm_SemLock(&client->lockClient);
2623+
2624+
for (tmpResp = client->firstPendResp;
2625+
tmpResp != NULL;
2626+
tmpResp = tmpResp->next) {
2627+
MqttClient_RespList_Remove(client, tmpResp);
2628+
}
2629+
wm_SemUnlock(&client->lockClient);
2630+
#endif
2631+
26122632
return MqttSocket_Disconnect(client);
26132633
}
26142634

0 commit comments

Comments
 (0)