From 94d04136f8beedbd34ca16158b5be3111a9cb7b4 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 6 Aug 2020 21:28:09 +0100 Subject: [PATCH] Fix potential memory leaks. Closes #1773. Closes #1774. Thanks to Yingpei Zeng. --- ChangeLog.txt | 1 + src/handle_publish.c | 5 ++++- src/handle_subscribe.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 6dc20f763b..35336acaf0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -19,6 +19,7 @@ Broker: than the generic "socket error". - Don't try to start DLT logging if DLT unavailable, to avoid a long delay when shutting down the broker. Closes #1735. +- Fix potential memory leaks. Closes #1773. Closes #1774. Client library: - Improved documentation around connect callback return codes. Close #1730. diff --git a/src/handle_publish.c b/src/handle_publish.c index 2504860dde..acbbec9372 100644 --- a/src/handle_publish.c +++ b/src/handle_publish.c @@ -109,7 +109,10 @@ int handle__publish(struct mosquitto_db *db, struct mosquitto *context) /* Handle properties */ if(context->protocol == mosq_p_mqtt5){ rc = property__read_all(CMD_PUBLISH, &context->in_packet, &properties); - if(rc) return rc; + if(rc){ + mosquitto__free(topic); + return rc; + } p = properties; p_prev = NULL; diff --git a/src/handle_subscribe.c b/src/handle_subscribe.c index 2ebf8ae48c..c42604ba4e 100644 --- a/src/handle_subscribe.c +++ b/src/handle_subscribe.c @@ -119,6 +119,8 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context) retain_handling = (subscription_options & 0x30); if(retain_handling == 0x30 || (subscription_options & 0xC0) != 0){ + mosquitto__free(sub); + mosquitto__free(payload); return MOSQ_ERR_PROTOCOL; } }