From bd59d98b91c4e6d40d76d838597d01b4e82fc713 Mon Sep 17 00:00:00 2001 From: Christophe Painchaud Date: Thu, 4 Feb 2021 23:29:25 +0100 Subject: [PATCH 1/2] 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) { From 9d9d314a0c667015fbd732e0ecb6fea8fe06f2bf Mon Sep 17 00:00:00 2001 From: Christophe Painchaud Date: Fri, 5 Feb 2021 17:50:34 +0100 Subject: [PATCH 2/2] fix syntax error --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6782b96..04fcafe 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -89,7 +89,7 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { if(_length != length){ _length = length; if( _value != nullptr) - delete _value; + delete[] _value; _value = new char[_length + 1]; } memset(_value, 0, _length + 1); // explicit null