Correct freeing of some persistence buffers

This commit is contained in:
Ian Craggs 2022-02-10 18:09:15 +00:00
parent 5780587c0e
commit 1964b6697a
2 changed files with 7 additions and 6 deletions

View File

@ -662,14 +662,14 @@ int MQTTAsync_restoreCommands(MQTTAsyncs* client)
cmd->seqno = atoi(strchr(msgkeys[i], '-')+1); /* key format is tag'-'seqno */
/* we can just append the commands to the list as they've already been sorted */
ListAppend(MQTTAsync_commands, cmd, sizeof(MQTTAsync_queuedCommand));
if (buffer)
free(buffer);
client->command_seqno = max(client->command_seqno, cmd->seqno);
commands_restored++;
if (cmd->command.type == PUBLISH)
client->noBufferedMessages++;
}
}
if (buffer)
free(buffer);
if (msgkeys[i])
free(msgkeys[i]);
i++;
@ -1246,11 +1246,11 @@ static int MQTTAsync_processCommand(void)
free(command->key);
command->key = NULL;
command = MQTTAsync_restoreCommand(buffer, buflen, MQTTVersion, command);
if (buffer)
free(buffer);
}
else
Log(LOG_ERROR, -1, "Error restoring command: rc %d from pget\n", rc);
if (buffer)
free(buffer);
}
MQTTAsync_unpersistCommand(command);
}

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp.
* Copyright (c) 2009, 2022 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
@ -886,10 +886,11 @@ int MQTTPersistence_restoreMessageQueue(Clients* c)
{
qe->seqno = atoi(strchr(msgkeys[i], '-')+1); /* key format is tag'-'seqno */
MQTTPersistence_insertInSeqOrder(c->messageQueue, qe, sizeof(MQTTPersistence_qEntry));
free(buffer);
c->qentry_seqno = max(c->qentry_seqno, qe->seqno);
entries_restored++;
}
if (buffer)
free(buffer);
}
if (msgkeys[i])
{