From 1cb47a2f3ba73f57e245e6ff41e034c74c11ad2c Mon Sep 17 00:00:00 2001 From: yuanjianmin Date: Wed, 12 Oct 2022 17:16:05 +0800 Subject: [PATCH] esp-tls: Fix memory leak in mbedtls ds peripheral when MBEDTLS_THREADING_C enabled --- components/esp-tls/esp_tls_mbedtls.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/components/esp-tls/esp_tls_mbedtls.c b/components/esp-tls/esp_tls_mbedtls.c index 104fdb8ef4..24c478476b 100644 --- a/components/esp-tls/esp_tls_mbedtls.c +++ b/components/esp-tls/esp_tls_mbedtls.c @@ -922,14 +922,17 @@ static esp_err_t esp_mbedtls_init_pk_ctx_for_ds(const void *pki) esp_ds_get_keylen )) != 0) { ESP_LOGE(TAG, "Error in mbedtls_pk_setup_rsa_alt, returned -0x%04X", -ret); mbedtls_print_error_msg(ret); - return ESP_FAIL; + ret = ESP_FAIL; + goto exit; } ret = esp_ds_init_data_ctx(((const esp_tls_pki_t*)pki)->esp_ds_data); if (ret != ESP_OK) { ESP_LOGE(TAG, "Failed to initialize DS parameters from nvs"); - return ESP_FAIL; + goto exit; } ESP_LOGD(TAG, "DS peripheral params initialized."); - return ESP_OK; +exit: + mbedtls_rsa_free(&rsakey); + return ret; } #endif /* CONFIG_ESP_TLS_USE_DS_PERIPHERAL */