Skip to content

Commit 5cd42a0

Browse files
committed
WiFiClientSecure: don't trash certificate and private key on stop()
1 parent 8f5a6fd commit 5cd42a0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

libraries/ESP8266WiFi/src/WiFiClientSecure.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern "C"
5353
uint8_t* default_private_key = 0;
5454
uint32_t default_private_key_len = 0;
5555
static bool default_private_key_dynamic = false;
56-
//
56+
static int s_pk_refcnt = 0;
5757
uint8_t* default_certificate = 0;
5858
uint32_t default_certificate_len = 0;
5959
static bool default_certificate_dynamic = false;
@@ -81,9 +81,6 @@ class SSLContext {
8181
if (_ssl_ctx_refcnt == 0) {
8282
ssl_ctx_free(_ssl_ctx);
8383
}
84-
85-
clear_private_key();
86-
clear_certificate();
8784
}
8885

8986
void ref() {
@@ -186,12 +183,17 @@ int SSLContext::_ssl_ctx_refcnt = 0;
186183

187184

188185
WiFiClientSecure::WiFiClientSecure() {
186+
++s_pk_refcnt;
189187
}
190188

191189
WiFiClientSecure::~WiFiClientSecure() {
192190
if (_ssl) {
193191
_ssl->unref();
194192
}
193+
if (--s_pk_refcnt == 0) {
194+
clear_private_key();
195+
clear_certificate();
196+
}
195197
}
196198

197199
WiFiClientSecure::WiFiClientSecure(const WiFiClientSecure& other)

0 commit comments

Comments
 (0)