Ensure that libcrypto and libssl do not unload until the process exits
authorMatt Caswell <matt@openssl.org>
Tue, 18 Oct 2016 13:13:25 +0000 (14:13 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 2 Nov 2016 23:37:28 +0000 (23:37 +0000)
commit4af9f7fe79ff82b90c16969b7e5871435056377b
treeccf99d9a93a2f8534726d784b27bee496b681397
parentf722f18e1a3560c13bd018711a30acca73c8d619
Ensure that libcrypto and libssl do not unload until the process exits

Because we use atexit() to cleanup after ourselves, this will cause a
problem if we have been dynamically loaded and then unloaded again: the
atexit() handler may no longer be there.

Most modern atexit() implementations can handle this, however there are
still difficulties if libssl gets unloaded before libcrypto, because of
the atexit() callback that libcrypto makes to libssl.

The most robust solution seems to be to ensure that libcrypto and libssl
never unload. This is done by simply deliberately leaking a dlopen()
reference to them.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit 5836780f436e03be231ff245f04f2f9f2f0ede91)
crypto/init.c