When I tried to build/run the indicator_openai example, (built with esp-idf v5.1.1), I found that multiple Chat GPT requests or DALL-E requests via mbedtls_send_then_recv() cause heap memory leaks so that eventually mbedtls_ssl_setup() will return the error:
**E (58463) openai: mbedtls_ssl_setup returned -0x7f00**
Additionally, in this case the goto exit; will result in these functions calls:
which cause the system to crash if/when mbedtls_ssl_setup() fails.
We can see that with each call to mbedtls_send_then_recv(), the free internal heap size reported by:
esp_get_free_internal_heap_size()
decreases continuously each time a request is sent to either Dall-E or Chat-GPT until there is not enough memory for mbedtls_ssl_setup(). I saw this issue on both the main branch (895d82a) as well as the tags/v1.03 branch.
It looks like mbed TLS resources are not being torn down in accordance with the documentation:
This fixes the issue and multiple openAI requests can be made. I'm not sure if this issue is also present in other examples since I've only looked at the indicator_openai example.
Additionally, in order to get the example to work properly I had to add the following back into indicator_openai/sdkconfig.defaults:
When I tried to build/run the indicator_openai example, (built with esp-idf v5.1.1), I found that multiple Chat GPT requests or DALL-E requests via mbedtls_send_then_recv() cause heap memory leaks so that eventually mbedtls_ssl_setup() will return the error:
Additionally, in this case the
goto exit;
will result in these functions calls:which cause the system to crash if/when mbedtls_ssl_setup() fails.
We can see that with each call to mbedtls_send_then_recv(), the free internal heap size reported by:
decreases continuously each time a request is sent to either Dall-E or Chat-GPT until there is not enough memory for mbedtls_ssl_setup(). I saw this issue on both the main branch (895d82a) as well as the tags/v1.03 branch.
It looks like mbed TLS resources are not being torn down in accordance with the documentation:
https://mbed-tls.readthedocs.io/en/latest/kb/how-to/mbedtls-tutorial/#teardown
This patch gets rid of the memory leaks and prevents the system from crashing in the event that mbedtls_ssl_setup() returns an error:
This fixes the issue and multiple openAI requests can be made. I'm not sure if this issue is also present in other examples since I've only looked at the indicator_openai example.
Additionally, in order to get the example to work properly I had to add the following back into indicator_openai/sdkconfig.defaults: