Memory leak on mbedtls_ctr_drbg_seed() and mbedtls_ecdh_gen_public() functions

Hi, i’m facing a memory leakage while using these two mbedtls functions mbedtls_ctr_drbg_seed() and mbedtls_ecdh_gen_public() in my project. I’m developing on a ESP32 WROVER-E with freeRTOS in C language. Enabling heap memory trace, i’m able to find two leakges in the above functions, this is the code snippet :

void internal_generated_keys_ecdh_ios_test( void )
{
ESP_ERROR_CHECK( heap_trace_init_standalone(trace_record, NUM_RECORDS) );
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
uint32_t heap_array[12] = {0};
uint8_t idx = 0;
heap_array[idx++] = esp_get_free_heap_size();

LOG_INFO(ECDH_TAG, "GENERATION AND PRINTING OF RANDOM EC KEYS");

unsigned char priv_pem[MAX_KEY_LEN];
unsigned char pub_pem[MAX_KEY_LEN];
unsigned char priv_der[MAX_KEY_LEN];
unsigned char pub_der[MAX_KEY_LEN];
unsigned char APP_ecdh_pub[65];
unsigned char MODULE_ecdh_pub[65];
memset(APP_ecdh_pub, 0, sizeof(APP_ecdh_pub));
unsigned char MODULE_shared_secret[32];
unsigned char APP_shared_secret[32]; 
mbedtls_ecdh_context keypair;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg1;
int ret = 1;
// Initialize the structures
mbedtls_ecdh_init(&keypair);
mbedtls_ecdh_setup( &keypair, MBEDTLS_ECP_DP_SECP256R1);
mbedtls_ctr_drbg_init(&ctr_drbg1);
mbedtls_entropy_init(&entropy);
heap_array[idx++] = esp_get_free_heap_size();
// Set up the random number generator
//char* persa = "ec_keygen";
const unsigned char random [9] = "ec_keygen";

ret = mbedtls_ctr_drbg_seed(&ctr_drbg1, mbedtls_entropy_func, (void*)(&entropy), random, sizeof(random));
if(ret)
{
    LOG_WARNING(ECDH_TAG, "Fail to call mbedtls_ctr_drbg_seed() function, error code : %d", ret);
}
//mbedtls_ctr_drbg_update( &ctr_drbg1,persa,sizeof(persa));
heap_array[idx++] = esp_get_free_heap_size();
// Generate the key pair
ret = mbedtls_ecdh_gen_public(&keypair.grp, &keypair.d, &keypair.Q, mbedtls_ctr_drbg_random, &ctr_drbg1);
heap_array[idx++] = esp_get_free_heap_size();
LOG_INFO(ECDH_TAG, "EC 256 R1 KEYS GENERATED"); 
unsigned char MODULE_ecdh_priv[32];
unsigned char MODULE_dhkey_message[64];

unsigned char APP_ecdh_priv[32];
unsigned char APP_dhkey_message[64];

if (ret == 0) 
{
    ret = mbedtls_mpi_write_binary(&keypair.d, MODULE_ecdh_priv, 32);
    //LOG_BUFFER_HEXDUMP_INFO(PRV_KEY_IOT_TAG, MODULE_ecdh_priv, 32);
    dump_buf("[PRIVKEY_IOT]  d: ", MODULE_ecdh_priv, 32);
    ret = mbedtls_mpi_write_binary(&keypair.Q.X, MODULE_dhkey_message, 32);
    //LOG_BUFFER_HEXDUMP_INFO(PUB_KEY_X_IOT_TAG, MODULE_dhkey_message, 32);
    dump_buf("[PUBKEY_IOT] Q.x: ", MODULE_dhkey_message, 32);
    ret = mbedtls_mpi_write_binary(&keypair.Q.Y, MODULE_dhkey_message + 32, 32);
    //LOG_BUFFER_HEXDUMP_INFO(PUB_KEY_Y_IOT_TAG, MODULE_dhkey_message+32, 32);
    dump_buf("[PUBKEY_IOT] Q.y: ", MODULE_dhkey_message + 32, 32);
} 
else 
{
    char error_buf[100];
    mbedtls_strerror(ret, error_buf, sizeof(error_buf));
    LOG_INFO(ECDH_TAG, "Key generation failed: %s\n", error_buf);
}  

}

This is the result of the heap trace:
2 allocations trace (100 entry buffer)
84 bytes (@ 0x3f941ec8) allocated CPU 0 ccount 0x34a79504 caller 0x400951bf:0x401f0ab4
84 bytes (@ 0x3f941f88) allocated CPU 0 ccount 0x34adea80 caller 0x400951bf:0x40095527
168 bytes ‘leaked’ in trace (2 allocations)
total allocations 2 total frees 67617

I’m using mbedtls with linked esp-idf SDK in the project. I’m not able to find any allocation in those two functions, moreover this leak happens just on the first call of the entire function (if i iterate internal_generated_keys_ecdh_ios_test(), leak happens just once).
I’m using esp-idf 4.4.4 and mbedTLS 2.28.1