From 27fb21e8f0011ee651762a19aa2a86c888e72ad7 Mon Sep 17 00:00:00 2001 From: Juergen Kosel Date: Tue, 3 Sep 2024 16:20:16 +0200 Subject: [PATCH] Release memory of pack->topic together with pack witin error cases of MQTTPacket_publish() As seen in https://github.com/eclipse/paho.mqtt.c/issues/1518 the memory allocated for pack-topic were not released in all cases. Signed-off-by: Juergen Kosel --- src/MQTTPacket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/MQTTPacket.c b/src/MQTTPacket.c index e44fa5a0..e44fa2c7 100644 --- a/src/MQTTPacket.c +++ b/src/MQTTPacket.c @@ -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; @@ -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)