Skip to content

Commit 39b6c55

Browse files
authored
Certificate isn't be free in case parse failure.
I met problem while I was working with the WiFiClientSecure. I tried to found the source of the problem, and I found it in the sll_client.cpp. Please check my contribution. I've open this problem in espressif#4335 but received no response.
1 parent 675a40b commit 39b6c55

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: libraries/WiFiClientSecure/src/ssl_client.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
122122
mbedtls_ssl_conf_ca_chain(&ssl_client->ssl_conf, &ssl_client->ca_cert, NULL);
123123
//mbedtls_ssl_conf_verify(&ssl_client->ssl_ctx, my_verify, NULL );
124124
if (ret < 0) {
125+
// free the ca_cert in the case parse failed, otherwise, the old ca_cert still in the heap memory, that lead to "out of memory" crash.
126+
mbedtls_x509_crt_free(&ssl_client->ca_cert);
125127
return handle_error(ret);
126128
}
127129
} else if (pskIdent != NULL && psKey != NULL) {
@@ -167,6 +169,8 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
167169

168170
ret = mbedtls_x509_crt_parse(&ssl_client->client_cert, (const unsigned char *)cli_cert, strlen(cli_cert) + 1);
169171
if (ret < 0) {
172+
// free the client_cert in the case parse failed, otherwise, the old client_cert still in the heap memory, that lead to "out of memory" crash.
173+
mbedtls_x509_crt_free(&ssl_client->client_cert);
170174
return handle_error(ret);
171175
}
172176

0 commit comments

Comments
 (0)