mbedtls_ssl_setup() allocs memory but you don't free it up in your example loop with mbedtls_ssl_free()
The simple fix I did was move the "*1. Start the connection" including the 'While' to just before the " * 4. Handshake"
See attached file.
ssl_client.zip