homieiot / homie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 308 forks source link

Free the char*-value before assigning a new strdup()'ed value #725

Closed Starcalc closed 2 years ago

Starcalc commented 2 years ago

If you're using the customizable and optional "settings" within the config.json, every time Homie.isConfigured() is called, some heap memory is lost to a strdup()'ed variable.

The variable is created via a strdup() at Config.cpp,141 and saved at HomieSetting.cpp,66.

This PR adds a new function ffree() to every template, it only contains actual code for the const char*-Setting.

I have several "custom" settings in the config.json and I'm calling Homie.isConfigured() frequently. I noticed that the free heap space kept decreasing, which led to a forced reboot after a while.