I'm working on https mbedtls and can't seem to recover all resources after finishing a function.
I log starting freeheap before calling the routine then log at various points trying to understand where memory is being consumed.
The https routine is a task. Max heap consumption is about 30k in the task. After finishing the https call, I do the following:
mbedtls_ssl_session_reset(&ssl);
mbedtls_net_free(&server_fd);
vTaskDelete(NULL);
Freeheap after the task has completed is 14k lower than what it was at task start. This is just a program snippet and nothing else is running.
mbedtls doesn't release all resources
Re: mbedtls doesn't release all resources
Hi rwel59,
There are some mbedTLS structures that the HTTPS example initializes once and then never frees as they're reused for each subsequent connection, but you may want to free these if you're completely done with mbedTLS.
For example, mbedtls_x509_crt_init() -> mbedtls_x509_crt_free(), mbedtls_ctr_drbg_init() -> mbedtls_ctr_drbg_free() and mbedtls_ssl_config_init() -> mbedtls_ssl_config_free(). Essentially any mbedtls_*_init has a matching mbedtls_*_free.
Also, there's a gotcha that TCP connections use a small amount of memory in the TIME_WAIT state until they expire. Although nothing like 14KB.
If these changes aren't enough to solve the problem, try the steps to find/resolve memory leaks in the heap debugging guide:
https://esp-idf.readthedocs.io/en/lates ... mory-leaks
Angus
There are some mbedTLS structures that the HTTPS example initializes once and then never frees as they're reused for each subsequent connection, but you may want to free these if you're completely done with mbedTLS.
For example, mbedtls_x509_crt_init() -> mbedtls_x509_crt_free(), mbedtls_ctr_drbg_init() -> mbedtls_ctr_drbg_free() and mbedtls_ssl_config_init() -> mbedtls_ssl_config_free(). Essentially any mbedtls_*_init has a matching mbedtls_*_free.
Also, there's a gotcha that TCP connections use a small amount of memory in the TIME_WAIT state until they expire. Although nothing like 14KB.
If these changes aren't enough to solve the problem, try the steps to find/resolve memory leaks in the heap debugging guide:
https://esp-idf.readthedocs.io/en/lates ... mory-leaks
Angus
Who is online
Users browsing this forum: Bing [Bot], Dennie and 113 guests