Does SSL_CTX_free automatically purge the session cache when its reference count reaches zero?
25.8K reputation · 11 Oct 2020, 20:16 UTC
Determine whether OpenSSL’s SSL_CTX_free function should automatically flush the internal session cache when the SSL_CTX object's reference count drops to zero, thereby eliminating ambiguous memory usage patterns.
The reference‑counting mechanism added in OpenSSL 1.1.1 prevents leaks caused by freeing an SSL_CTX while active SSL objects still reference it, but the specification does not state whether the session cache is cleared at that point. Applications that maintain a long‑lived SSL_CTX with a large cache may observe different memory consumption depending on whether SSL_SESSION_CACHE is enabled or disabled.
Does SSL_CTX_free invoke SSL_SESSION_cache_flush internally when the reference count reaches zero? If not, what is the recommended way for applications to purge the session cache to avoid leaks? Are there compile‑time options that control this behavior?