Synchronize assign msgid on mqttcommand mutex #880

This commit is contained in:
Ian Craggs 2020-05-13 18:52:15 +01:00
parent 46c5ccb5a8
commit c7f6161b4c
1 changed files with 2 additions and 0 deletions

View File

@ -3470,6 +3470,7 @@ static int MQTTAsync_assignMsgId(MQTTAsyncs* m)
start_msgid = m->c->msgID;
msgid = start_msgid;
MQTTAsync_lock_mutex(mqttcommand_mutex);
msgid = (msgid == MAX_MSG_ID) ? 1 : msgid + 1;
while (ListFindItem(commands, &msgid, cmdMessageIDCompare) ||
ListFindItem(m->c->outboundMsgs, &msgid, messageIDCompare) ||
@ -3482,6 +3483,7 @@ static int MQTTAsync_assignMsgId(MQTTAsyncs* m)
break;
}
}
MQTTAsync_unlock_mutex(mqttcommand_mutex);
if (msgid != 0)
m->c->msgID = msgid;
if (locked)