aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2013-06-11 16:28:56 +0200
committerSverker Eriksson <[email protected]>2013-06-11 16:29:25 +0200
commit6b1147bd90960772257e12ab6fa66ec9aaacc48a (patch)
treea66a6a881bdd6b66fcddd9c752bec716f56a8e7c /lib
parent9919508b2cc177ec4afdb53bb9d20563973461f8 (diff)
downloadotp-6b1147bd90960772257e12ab6fa66ec9aaacc48a.tar.gz
otp-6b1147bd90960772257e12ab6fa66ec9aaacc48a.tar.bz2
otp-6b1147bd90960772257e12ab6fa66ec9aaacc48a.zip
crypto: Fix bug with takover of EC resource type
enif_open_resource_type() must be called even during repeated loading of same library. Otherwise the resource type will be deallocated when the old module instance is purged.
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/c_src/crypto.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 00abeb9990..35de3dbf0c 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -590,6 +590,14 @@ static int init(ErlNifEnv* env, ERL_NIF_TERM load_info)
PRINTF_ERR1("CRYPTO: Invalid load_info '%T'", load_info);
return 0;
}
+
+#if defined(HAVE_EC)
+ res_type_ec_key = enif_open_resource_type(env,NULL,"crypto.EC_KEY",
+ ec_key_dtor,
+ ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER,
+ NULL);
+#endif
+
if (library_refc > 0) {
/* Repeated loading of this library (module upgrade).
* Atoms and callbacks are already set, we are done.
@@ -633,11 +641,6 @@ static int init(ErlNifEnv* env, ERL_NIF_TERM load_info)
for (i = 0; i < EC_CURVES_CNT; i++)
ec_curves[i].atom = enif_make_atom(env,ec_curves[i].name);
-
- res_type_ec_key = enif_open_resource_type(env,NULL,"crypto.EC_KEY",
- ec_key_dtor,
- ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER,
- NULL);
#endif
init_digest_types(env);