*/
#include "internal/cryptlib_int.h"
+#include "internal/thread_once.h"
#include <openssl/lhash.h>
/*
static CRYPTO_RWLOCK *ex_data_lock = NULL;
static CRYPTO_ONCE ex_data_init = CRYPTO_ONCE_STATIC_INIT;
-static void do_ex_data_init(void)
+DEFINE_RUN_ONCE_STATIC(do_ex_data_init)
{
+ OPENSSL_init_crypto(0, NULL);
ex_data_lock = CRYPTO_THREAD_lock_new();
+ return ex_data_lock != NULL;
}
/*
return NULL;
}
- CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);
+ if (!RUN_ONCE(&ex_data_init, do_ex_data_init)) {
+ CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_MALLOC_FAILURE);
+ return NULL;
+ }
if (ex_data_lock == NULL) {
/*
{
}
-static int dummy_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from,
+static int dummy_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from,
void *from_d, int idx,
long argl, void *argp)
{
* for each index in the class used by this variable
*/
int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
- CRYPTO_EX_DATA *from)
+ const CRYPTO_EX_DATA *from)
{
int mx, j, i;
char *ptr;
int mx, i;
EX_CALLBACKS *ip;
void *ptr;
+ EX_CALLBACK *f;
EX_CALLBACK *stack[10];
EX_CALLBACK **storage = NULL;
if ((ip = get_and_lock(class_index)) == NULL)
- return;
+ goto err;
mx = sk_EX_CALLBACK_num(ip->meth);
if (mx > 0) {
}
CRYPTO_THREAD_unlock(ex_data_lock);
- if (mx > 0 && storage == NULL) {
- CRYPTOerr(CRYPTO_F_CRYPTO_FREE_EX_DATA, ERR_R_MALLOC_FAILURE);
- return;
- }
for (i = 0; i < mx; i++) {
- if (storage[i] && storage[i]->free_func) {
+ if (storage != NULL)
+ f = storage[i];
+ else {
+ CRYPTO_THREAD_write_lock(ex_data_lock);
+ f = sk_EX_CALLBACK_value(ip->meth, i);
+ CRYPTO_THREAD_unlock(ex_data_lock);
+ }
+ if (f != NULL && f->free_func != NULL) {
ptr = CRYPTO_get_ex_data(ad, i);
- storage[i]->free_func(obj, ptr, ad, i,
- storage[i]->argl, storage[i]->argp);
+ f->free_func(obj, ptr, ad, i, f->argl, f->argp);
}
}
if (storage != stack)
OPENSSL_free(storage);
+ err:
sk_void_free(ad->sk);
ad->sk = NULL;
}