diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c index 03f5cb28..ee40e2f7 100644 --- a/src/MQTTAsync.c +++ b/src/MQTTAsync.c @@ -718,6 +718,12 @@ static MQTTAsync_queuedCommand* MQTTAsync_restoreCommand(char* buffer, int bufle case SUBSCRIBE: command->details.sub.count = *(int*)ptr; ptr += sizeof(int); + + if (command->details.sub.count > 0) + { + command->details.sub.topics = (char **)malloc(sizeof(char *) * command->details.sub.count); + command->details.sub.qoss = (int *)malloc(sizeof(int) * command->details.sub.count); + } for (i = 0; i < command->details.sub.count; ++i) { @@ -733,8 +739,13 @@ static MQTTAsync_queuedCommand* MQTTAsync_restoreCommand(char* buffer, int bufle break; case UNSUBSCRIBE: - command->details.sub.count = *(int*)ptr; + command->details.unsub.count = *(int*)ptr; ptr += sizeof(int); + + if (command->details.unsub.count > 0) + { + command->details.unsub.topics = (char **)malloc(sizeof(char *) * command->details.unsub.count); + } for (i = 0; i < command->details.unsub.count; ++i) {