Skip to content

Commit 00440cd

Browse files
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.
1 parent b930c4c commit 00440cd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: libraries/ESP8266WiFi/src/CertStoreBearSSL.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ int CertStore::initCertStore(FS &fs, const char *indexFileName, const char *data
8282

8383
_fs = &fs;
8484

85+
// In case initCertStore called multiple times, don't leak old filenames
86+
free(_indexName);
87+
free(_dataName);
88+
8589
// No strdup_P, so manually do it
8690
_indexName = (char *)malloc(strlen_P(indexFileName) + 1);
8791
_dataName = (char *)malloc(strlen_P(dataFileName) + 1);

0 commit comments

Comments
 (0)