Skip to content

Commit

Permalink
Release memory of pack->topic together with pack witin error cases of…
Browse files Browse the repository at this point in the history
… MQTTPacket_publish()

As seen in
#1518
the memory allocated for pack-topic were not released in all cases.

Signed-off-by: Juergen Kosel <[email protected]>
  • Loading branch information
JuergenKosel committed Sep 3, 2024
1 parent 0521dc5 commit 27fb21e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/MQTTPacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ void* MQTTPacket_publish(int MQTTVersion, unsigned char aHeader, char* data, siz
{
if (enddata - curdata < 2) /* Is there enough data for the msgid? */
{
free(pack->topic);
pack->topic = NULL;
free(pack);
pack = NULL;
goto exit;
Expand All @@ -589,6 +591,8 @@ void* MQTTPacket_publish(int MQTTVersion, unsigned char aHeader, char* data, siz
pack->properties = props;
if (MQTTProperties_read(&pack->properties, &curdata, enddata) != 1)
{
free(pack->topic);
pack->topic = NULL;
if (pack->properties.array)
free(pack->properties.array);
if (pack)
Expand Down

0 comments on commit 27fb21e

Please sign in to comment.