Hi Satya,

The function you're looking for is mbedtls_ssl_free(). It won't free the context structure itself, but will free all the memory that had been allocated to member variables.

Generally speaking, for each structure xxx, the mbedtls_xxx_free() function does recursively frees all ressources (memory, mutexes, whatever) held by member variables, and also securily wipes out secrets from memory, so it's good to always call that function even when there are no ressources to be freed.

Regards,
Manuel.

From: Satya Prakash Prasad via mbed-tls <mbed-tls@lists.trustedfirmware.org>
Sent: 27 February 2024 15:49
To: mbed-tls@lists.trustedfirmware.org <mbed-tls@lists.trustedfirmware.org>
Subject: [mbed-tls] Release all memory held by mbedtls_ssl_context
 
Hi,

We are writing a client code which can accept or decline connection to the server - so for each connection I understand there is a mbedtls_ssl_context data established. Once the same is closed or not required we need to do deinitialize or free memory allocated to its member variables like - we need to free all memory allocated since we need it back else our application will run out of memory like:

        os_free(mbed_ctx->handshake);
        os_free(mbed_ctx->transform_negotiate);
        os_free(mbed_ctx->session_negotiate);
        os_free(mbed_ctx->in_buf);
        os_free(mbed_ctx->out_buf);

But there are many member variables which also need to free memory if allocated and assigned to it.

Is there a function / method that can free all memory for mbedtls_ssl_context instance variable?

Thanks in advance.

Regards,
Prakash