Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak on windows with statically linked openssl #880

Open
DenisRazinkin opened this issue Oct 23, 2023 · 0 comments
Open

Memory leak on windows with statically linked openssl #880

DenisRazinkin opened this issue Oct 23, 2023 · 0 comments

Comments

@DenisRazinkin
Copy link

I use statically linked openssl to verify singature of client token inside of oatpp ENDPOINT handlers.
Oatpp simple mode creates a new thread for every connection.
Eventually, memory leak is caused by static linking, because in this case openssl doesn't call OPENSSL_thread_stop at thread exit.
But it would be great if oatpp provided some callback to free memory at stop of a detached thread.

https://www.openssl.org/docs/man1.1.1/man3/OPENSSL_atexit.html
Resources local to a thread are deallocated automatically when the thread exits (e.g. in a pthreads environment, when pthread_exit() is called). On Windows platforms this is done in response to a DLL_THREAD_DETACH message being sent to the libcrypto32.dll entry point. Some windows functions may cause threads to exit without sending this message (for example ExitProcess()). If the application uses such functions, then the application must free up OpenSSL resources directly via a call to OPENSSL_thread_stop() on each thread. Similarly this message will also not be sent if OpenSSL is linked statically, and therefore applications using static linking should also call OPENSSL_thread_stop() on each thread. Additionally if OpenSSL is loaded dynamically via LoadLibrary() and the threads are not destroyed until after FreeLibrary() is called then each thread should call OPENSSL_thread_stop() prior to the FreeLibrary() call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant