TLS: Fix memory leak with OpenSSL

Based on the patch submitted by midnight2k