From 3a92e82e9749110ae03ba95e0c5bd16332393fbc Mon Sep 17 00:00:00 2001 From: Yuan Jian Min Date: Mon, 26 Sep 2022 19:15:04 +0800 Subject: [PATCH] esp-tls: socket will be set to -1 and will not be closed --- components/esp-tls/esp_tls_mbedtls.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/esp-tls/esp_tls_mbedtls.c b/components/esp-tls/esp_tls_mbedtls.c index e59c2361f9..d403697ba9 100644 --- a/components/esp-tls/esp_tls_mbedtls.c +++ b/components/esp-tls/esp_tls_mbedtls.c @@ -202,8 +202,11 @@ void esp_mbedtls_conn_delete(esp_tls_t *tls) if (tls != NULL) { esp_mbedtls_cleanup(tls); if (tls->is_tls) { - mbedtls_net_free(&tls->server_fd); - tls->sockfd = tls->server_fd.fd; + if (tls->server_fd.fd != -1) { + mbedtls_net_free(&tls->server_fd); + /* Socket is already closed by `mbedtls_net_free` and hence also change assignment of its copy to an invalid value */ + tls->sockfd = -1; + } } } }