Browse Source

Fix memory leak in MQTT connection method

fastled
Xose Pérez 7 years ago
parent
commit
042ceb904c
1 changed files with 6 additions and 2 deletions
  1. +6
    -2
      code/espurna/mqtt.ino

+ 6
- 2
code/espurna/mqtt.ino View File

@ -139,8 +139,7 @@ void mqttConnect() {
if (!mqtt.connected()) {
char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str());
if (strlen(host) == 0) return;
if (getSetting("mqttServer", MQTT_SERVER).length() == 0) return;
// Last option: reconnect to wifi after MQTT_MAX_TRIES attemps in a row
#if MQTT_MAX_TRIES > 0
@ -161,6 +160,7 @@ void mqttConnect() {
mqtt.disconnect();
char * host = strdup(getSetting("mqttServer", MQTT_SERVER).c_str());
unsigned int port = getSetting("mqttPort", MQTT_PORT).toInt();
char * user = strdup(getSetting("mqttUser").c_str());
char * pass = strdup(getSetting("mqttPassword").c_str());
@ -176,6 +176,10 @@ void mqttConnect() {
DEBUG_MSG("\n");
mqtt.connect();
free(host);
free(user);
free(pass);
}
}


Loading…
Cancel
Save