Is it safe to call OPENSSL_thread_stop multiple times? #22831
-
A libcurl dll built with statically linked OpenSSL may cause a memory leak because OPENSSL_thread_stop is not called. We could call OPENSSL_thread_stop in our DllMain on DLL_THREAD_DETACH, however if OpenSSL is a DLL then it also calls that function in its DllMain on DLL_THREAD_DETACH. Is it allowed to call the function twice? I do not see it documented and I can't tell from the source. It looks like the function tries to retrieve a tls local value and passes it on to init_thread_remove_handlers even if that value is NULL. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, I believe this should be fine.
It then calls Finally it calls |
Beta Was this translation helpful? Give feedback.
Yes, I believe this should be fine.
OPENSSL_thread_stop
callsinit_get_thread_local
to obtain the THREAD_EVENT_HANDLER list. On a second call ofOPENSSL_thread_stop
this return value should be NULL.It then calls
init_thread_stop
with that value - which just immediately returns if the handler list is NULL, andinit_thread_remove_handlers
which is a no-op if the handler list is NULL.Finally it calls
OPENSSL_free
with the NULL pointer - which is also fine and a no-op.