Skip to content

Commit

Permalink
Merge branch 'sverker/crypto/musl-init-restart-fix' into maint
Browse files Browse the repository at this point in the history
OTP-18670
  • Loading branch information
sverker committed Jun 30, 2023
2 parents 6281829 + fae85c2 commit 8822a39
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
17 changes: 14 additions & 3 deletions lib/crypto/c_src/algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void init_rsa_opts_types(ErlNifEnv* env);

void init_algorithms_types(ErlNifEnv* env)
{
mtx_init_curve_types = enif_mutex_create("init_curve_types");
#ifdef HAS_3_0_API
#else
init_hash_types(env);
Expand All @@ -62,9 +61,21 @@ void init_algorithms_types(ErlNifEnv* env)
/* ciphers and macs are initiated statically */
}

void cleanup_algorithms_types(ErlNifEnv* env)

int create_curve_mutex(void)
{
if (!mtx_init_curve_types) {
mtx_init_curve_types = enif_mutex_create("init_curve_types");
}
return !!mtx_init_curve_types;
}

void destroy_curve_mutex(void)
{
enif_mutex_destroy(mtx_init_curve_types);
if (mtx_init_curve_types) {
enif_mutex_destroy(mtx_init_curve_types);
mtx_init_curve_types = NULL;
}
}

/*================================================================
Expand Down
3 changes: 2 additions & 1 deletion lib/crypto/c_src/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

#include "common.h"

int create_curve_mutex(void);
void destroy_curve_mutex(void);
void init_algorithms_types(ErlNifEnv* env);
void cleanup_algorithms_types(ErlNifEnv* env);

ERL_NIF_TERM hash_algorithms(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM pubkey_algorithms(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
Expand Down
4 changes: 3 additions & 1 deletion lib/crypto/c_src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
if (!create_engine_mutex(env)) {
return __LINE__;
}
if (!create_curve_mutex())
return __LINE__;

#ifdef HAS_3_0_API
prov_cnt = 0;
Expand Down Expand Up @@ -333,7 +335,7 @@ static int upgrade(ErlNifEnv* env, void** priv_data, void** old_priv_data,
static void unload(ErlNifEnv* env, void* priv_data)
{
if (--library_refc == 0) {
cleanup_algorithms_types(env);
destroy_curve_mutex();
destroy_engine_mutex(env);
}

Expand Down

0 comments on commit 8822a39

Please sign in to comment.