From 9799ee20118bd13d448b17a7c8729df0275c38e1 Mon Sep 17 00:00:00 2001 From: frank eden Date: Tue, 31 Oct 2017 17:08:35 +1100 Subject: [PATCH] Fix Memory Leak in Mqtt --- Sming/Services/libemqtt/libemqtt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sming/Services/libemqtt/libemqtt.c b/Sming/Services/libemqtt/libemqtt.c index 28a97a14c6..de86c37525 100644 --- a/Sming/Services/libemqtt/libemqtt.c +++ b/Sming/Services/libemqtt/libemqtt.c @@ -215,6 +215,7 @@ int mqtt_set_clientid(mqtt_broker_handle_t* broker, const char* clientid) { int mqtt_init_auth(mqtt_broker_handle_t* broker, const char* username, const char* password) { if(username && username[0] != '\0') { + free(broker->username); broker->username = (char *)malloc(strlen(username)+1); if(broker->username==NULL) { return -1; @@ -224,6 +225,7 @@ int mqtt_init_auth(mqtt_broker_handle_t* broker, const char* username, const cha } if(password && password[0] != '\0') { + free(broker->username); broker->password = (char *)malloc(strlen(password)+1); if (broker->password == NULL) { return -1;