X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbio%2Fbio_meth.c;h=c5f9f7e8e75f23531c6e93a5f9b540aa2603754b;hp=7754b003947eab62878593b050a31c9b64e6f81d;hb=5a7ad1f08bfccbdad0f20920f9c284bba036fb70;hpb=6b1f413c3a8563a53e1b41d48d870c010541c7f5 diff --git a/crypto/bio/bio_meth.c b/crypto/bio/bio_meth.c index 7754b00394..c5f9f7e8e7 100644 --- a/crypto/bio/bio_meth.c +++ b/crypto/bio/bio_meth.c @@ -8,14 +8,26 @@ */ #include "bio_lcl.h" +#include -CRYPTO_RWLOCK *bio_type_lock; -static int bio_count = BIO_TYPE_START; +CRYPTO_RWLOCK *bio_type_lock = NULL; +static CRYPTO_ONCE bio_type_init = CRYPTO_ONCE_STATIC_INIT; + +DEFINE_RUN_ONCE_STATIC(do_bio_type_init) +{ + bio_type_lock = CRYPTO_THREAD_lock_new(); + return bio_type_lock != NULL; +} int BIO_get_new_index() { + static int bio_count = BIO_TYPE_START; int newval; + if (!RUN_ONCE(&bio_type_init, do_bio_type_init)) { + BIOerr(BIO_F_BIO_GET_NEW_INDEX, ERR_R_MALLOC_FAILURE); + return -1; + } if (!CRYPTO_atomic_add(&bio_count, 1, &newval, bio_type_lock)) return -1; return newval;