diff --git a/wled00/mqtt.cpp b/wled00/mqtt.cpp index 66239b6c..23a1bd03 100644 --- a/wled00/mqtt.cpp +++ b/wled00/mqtt.cpp @@ -62,17 +62,10 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties DEBUG_PRINTLN(F("no payload -> leave")); return; } - char* payloadStr; - bool alloc = false; - // check if payload is 0-terminated - if (payload[len-1] == '\0') { - payloadStr = payload; - } else { - payloadStr = new char[len+1]; - strncpy(payloadStr, payload, len); - payloadStr[len] = '\0'; - alloc = true; - } + //make a copy of the payload to 0-terminate it + char* payloadStr = new char[len+1]; + strncpy(payloadStr, payload, len); + payloadStr[len] = '\0'; if (payloadStr == nullptr) return; //no mem DEBUG_PRINTLN(payloadStr); @@ -86,7 +79,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties } else { // Non-Wled Topic used here. Probably a usermod subscribed to this topic. usermods.onMqttMessage(topic, payloadStr); - if (alloc) delete[] payloadStr; + delete[] payloadStr; return; } } @@ -113,7 +106,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties // topmost topic (just wled/MAC) parseMQTTBriPayload(payloadStr); } - if (alloc) delete[] payloadStr; + delete[] payloadStr; } diff --git a/wled00/wled.h b/wled00/wled.h index 957f473e..4ebdd23e 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2105120 +#define VERSION 2105170 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG