From bd59d98b91c4e6d40d76d838597d01b4e82fc713 Mon Sep 17 00:00:00 2001 From: Christophe Painchaud Date: Thu, 4 Feb 2021 23:29:25 +0100 Subject: [PATCH] fix potential memory leak in WiFiManagerParameter::setValue --- WiFiManager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f751dae..6782b96 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -86,8 +86,12 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { // // return false; //@todo bail // } - _length = length; - _value = new char[_length + 1]; + if(_length != length){ + _length = length; + if( _value != nullptr) + delete _value; + _value = new char[_length + 1]; + } memset(_value, 0, _length + 1); // explicit null if (defaultValue != NULL) {