aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2018-05-17 19:29:45 +0200
committerSverker Eriksson <[email protected]>2018-05-17 19:29:45 +0200
commit93b48f41103a7491ae1c6955ff5ceb5ee15ee666 (patch)
tree00f8ba084b3c10a9dc520b3b4e91c79907f37ee1 /lib
parent4b8a81dd49fbeda8f2da118d43f3690a61f2283a (diff)
downloadotp-93b48f41103a7491ae1c6955ff5ceb5ee15ee666.tar.gz
otp-93b48f41103a7491ae1c6955ff5ceb5ee15ee666.tar.bz2
otp-93b48f41103a7491ae1c6955ff5ceb5ee15ee666.zip
crypto: Robustify the do-once-initialization
Introduce boolean 'library_initialized' that is set once and never cleared as that is how initialization must be done. Kept 'library_refc' as it may be interesting for debugging. Moved the three init_*_types() functions last as those must only be called once and there were error cases bailing out after them.
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/c_src/crypto.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 9e7e1e81ae..5f10e93728 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -528,6 +528,7 @@ static int zero_terminate(ErlNifBinary bin, char **buf);
#endif
static int library_refc = 0; /* number of users of this dynamic library */
+static int library_initialized = 0;
static ErlNifFunc nif_funcs[] = {
{"info_lib", 0, info_lib},
@@ -991,7 +992,7 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
}
#endif
- if (library_refc > 0) {
+ if (library_initialized) {
/* Repeated loading of this library (module upgrade).
* Atoms and callbacks are already set, we are done.
*/
@@ -1101,10 +1102,6 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
atom_password = enif_make_atom(env,"password");
#endif
- init_digest_types(env);
- init_cipher_types(env);
- init_algorithms_types(env);
-
#ifdef HAVE_DYNAMIC_CRYPTO_LIB
{
void* handle;
@@ -1150,6 +1147,11 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
}
#endif /* OPENSSL_THREADS */
+ init_digest_types(env);
+ init_cipher_types(env);
+ init_algorithms_types(env);
+
+ library_initialized = 1;
return 0;
}