Skip to content

Commit

Permalink
Free some allocated memory under some circumstances
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs committed May 25, 2023
1 parent 5ce3222 commit 9613cf4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/MQTTPersistence.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9613cf4

Please sign in to comment.