Skip to content

Commit

Permalink
Fix double lock of lockRecv.
Browse files Browse the repository at this point in the history
  • Loading branch information
philljj committed Mar 21, 2024
1 parent 9bc9856 commit 57805f8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ static int MqttClient_CancelMessage(MqttClient *client, MqttObject* msg);
s->sem = NULL;
return 0;
}

int wm_SemLock(wm_Sem *s) {
dispatch_semaphore_wait(s->sem, DISPATCH_TIME_FOREVER);
return 0;
Expand Down Expand Up @@ -275,11 +274,14 @@ static int MqttReadStart(MqttClient* client, MqttMsgStat* stat)
{
int rc = MQTT_CODE_SUCCESS;

#ifdef WOLFMQTT_DEBUG_CLIENT
#if defined(WOLFMQTT_DEBUG_CLIENT) || !defined(WOLFMQTT_ALLOW_NODATA_UNLOCK)
#ifdef WOLFMQTT_DEBUG_CLIENT
if (stat->isReadActive) {
MQTT_TRACE_MSG("Warning, recv already locked!");
rc = MQTT_CODE_ERROR_SYSTEM;
}
#endif /* WOLFMQTT_DEBUG_CLIENT */
#ifndef WOLFMQTT_ALLOW_NODATA_UNLOCK
/* detect if a read is already in progress */
#ifdef WOLFMQTT_MULTITHREAD
if (wm_SemLock(&client->lockClient) == 0)
Expand All @@ -293,9 +295,11 @@ static int MqttReadStart(MqttClient* client, MqttMsgStat* stat)
wm_SemUnlock(&client->lockClient);
#endif
}
if (rc != 0)
#endif /* WOLFMQTT_ALLOW_NODATA_UNLOCK */
if (rc != MQTT_CODE_SUCCESS) {
return rc;
#endif /* WOLFMQTT_DEBUG_CLIENT */
}
#endif /* WOLFMQTT_DEBUG_CLIENT || !WOLFMQTT_ALLOW_NODATA_UNLOCK */

#ifdef WOLFMQTT_MULTITHREAD
rc = wm_SemLock(&client->lockRecv);
Expand Down

0 comments on commit 57805f8

Please sign in to comment.