Isn't this a well-discussed issue already, and not specific to TPM?
We faced a similar issue (we use OpenSSL). OpenSSL does have OPENSSL_secure_malloc() which prevents sensitive memory from being dumped. However, the problem is that not all paths use the secure allocator. For example, this issue: https://github.com/openssl/openssl/issues/27603
Not sure if this has changed in OpenSSL 4.x, but it is certainly something desirable.