From 6b1147bd90960772257e12ab6fa66ec9aaacc48a Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 11 Jun 2013 16:28:56 +0200 Subject: 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. --- lib/crypto/c_src/crypto.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') 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); -- cgit v1.2.3