esp-tls: add api to free client session

Free session with mbedtls api to avoid mem-leak
This commit is contained in:
Li Jingyi 2022-05-17 17:14:57 +08:00
parent 68ddce7c0b
commit 6d58008119
4 changed files with 29 additions and 0 deletions

View File

@ -40,6 +40,7 @@ static const char *TAG = "esp-tls";
#define _esp_tls_conn_delete esp_mbedtls_conn_delete
#define _esp_tls_net_init esp_mbedtls_net_init
#define _esp_tls_get_client_session esp_mbedtls_get_client_session
#define _esp_tls_free_client_session esp_mbedtls_free_client_session
#define _esp_tls_get_ssl_context esp_mbedtls_get_ssl_context
#ifdef CONFIG_ESP_TLS_SERVER
#define _esp_tls_server_session_create esp_mbedtls_server_session_create
@ -564,6 +565,11 @@ esp_tls_client_session_t *esp_tls_get_client_session(esp_tls_t *tls)
{
return _esp_tls_get_client_session(tls);
}
void esp_tls_free_client_session(esp_tls_client_session_t *client_session)
{
_esp_tls_free_client_session(client_session);
}
#endif /* CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS */

View File

@ -633,6 +633,16 @@ esp_err_t esp_tls_plain_tcp_connect(const char *host, int hostlen, int port, con
* NULL on Failure
*/
esp_tls_client_session_t *esp_tls_get_client_session(esp_tls_t *tls);
/**
* @brief Free the client session
*
* This function should be called after esp_tls_get_client_session().
*
* @param[in] client_session context as esp_tls_client_session_t
*
*/
void esp_tls_free_client_session(esp_tls_client_session_t *client_session);
#endif /* CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS */
#ifdef __cplusplus
}

View File

@ -174,6 +174,14 @@ esp_tls_client_session_t *esp_mbedtls_get_client_session(esp_tls_t *tls)
return client_session;
}
void esp_mbedtls_free_client_session(esp_tls_client_session_t *client_session)
{
if (client_session) {
mbedtls_ssl_session_free(&(client_session->saved_session));
free(client_session);
}
}
#endif /* CONFIG_ESP_TLS_CLIENT_SESSION_TICKETS */
int esp_mbedtls_handshake(esp_tls_t *tls, const esp_tls_cfg_t *cfg)

View File

@ -110,6 +110,11 @@ esp_err_t set_client_config(const char *hostname, size_t hostlen, esp_tls_cfg_t
* Internal Callback for mbedtls_get_client_session
*/
esp_tls_client_session_t *esp_mbedtls_get_client_session(esp_tls_t *tls);
/**
* Internal Callback for mbedtls_free_client_session
*/
void esp_mbedtls_free_client_session(esp_tls_client_session_t *client_session);
#endif
/**