diff --git a/src/MQTTPersistence.c b/src/MQTTPersistence.c index 7e6e11e8..7cf47774 100644 --- a/src/MQTTPersistence.c +++ b/src/MQTTPersistence.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2022 IBM Corp. + * Copyright (c) 2009, 2023 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 @@ -340,16 +340,29 @@ int MQTTPersistence_restorePackets(Clients *c) buffer = NULL; } if (msgkeys[i]) + { free(msgkeys[i]); + msgkeys[i] = NULL; + } i++; } - if (msgkeys) - free(msgkeys); } Log(TRACE_MINIMUM, -1, "%d sent messages and %d received messages restored for client %s\n", msgs_sent, msgs_rcvd, c->clientID); MQTTPersistence_wrapMsgID(c); exit: + if (msgkeys) + { + int i = 0; + for (i = 0; i < nkeys; ++i) + { + if (msgkeys[i]) + free(msgkeys[i]); + } + free(msgkeys); + } + if (buffer) + free(buffer); FUNC_EXIT_RC(rc); return rc; }