From 00440cd84a4ed9467de6305cb768875e09c12303 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 17 Jan 2020 10:10:17 -0800 Subject: [PATCH] Remove memory leak on multiple calls to initCertStore (#7021) In some cases, `initCertStore` may need to be called multiple times (i.e. to update certs w/oa reboot). In that case, the saved file names leaked when the new ones were `malloc()`'d. Fix by freeing the old strings, if present. --- libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp b/libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp index 8affc7e01b..905efde2ba 100644 --- a/libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp +++ b/libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp @@ -82,6 +82,10 @@ int CertStore::initCertStore(FS &fs, const char *indexFileName, const char *data _fs = &fs; + // In case initCertStore called multiple times, don't leak old filenames + free(_indexName); + free(_dataName); + // No strdup_P, so manually do it _indexName = (char *)malloc(strlen_P(indexFileName) + 1); _dataName = (char *)malloc(strlen_P(dataFileName) + 1);