From a22d1966bb230c335602ff79ca3356137d16b3e6 Mon Sep 17 00:00:00 2001 From: Pauli Date: Thu, 22 Jun 2023 09:26:38 +1000 Subject: bio: update to structure based atomics Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21260) --- crypto/bio/bio_lib.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'crypto/bio/bio_lib.c') diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 2848d55934..209b74730e 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -88,22 +88,17 @@ BIO *BIO_new_ex(OSSL_LIB_CTX *libctx, const BIO_METHOD *method) bio->libctx = libctx; bio->method = method; bio->shutdown = 1; - bio->references = 1; - if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data)) + if (!CRYPTO_NEW_REF(&bio->references, 1)) goto err; - bio->lock = CRYPTO_THREAD_lock_new(); - if (bio->lock == NULL) { - ERR_raise(ERR_LIB_BIO, ERR_R_CRYPTO_LIB); - CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); + if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data)) goto err; - } if (method->create != NULL && !method->create(bio)) { ERR_raise(ERR_LIB_BIO, ERR_R_INIT_FAIL); CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); - CRYPTO_THREAD_lock_free(bio->lock); + CRYPTO_FREE_REF(&bio->references); goto err; } if (method->create == NULL) @@ -112,6 +107,7 @@ BIO *BIO_new_ex(OSSL_LIB_CTX *libctx, const BIO_METHOD *method) return bio; err: + CRYPTO_FREE_REF(&bio->references); OPENSSL_free(bio); return NULL; } @@ -128,7 +124,7 @@ int BIO_free(BIO *a) if (a == NULL) return 0; - if (CRYPTO_DOWN_REF(&a->references, &ret, a->lock) <= 0) + if (CRYPTO_DOWN_REF(&a->references, &ret) <= 0) return 0; REF_PRINT_COUNT("BIO", a); @@ -147,7 +143,7 @@ int BIO_free(BIO *a) CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); - CRYPTO_THREAD_lock_free(a->lock); + CRYPTO_FREE_REF(&a->references); OPENSSL_free(a); @@ -193,7 +189,7 @@ int BIO_up_ref(BIO *a) { int i; - if (CRYPTO_UP_REF(&a->references, &i, a->lock) <= 0) + if (CRYPTO_UP_REF(&a->references, &i) <= 0) return 0; REF_PRINT_COUNT("BIO", a); @@ -858,7 +854,7 @@ void BIO_free_all(BIO *bio) while (bio != NULL) { b = bio; - ref = b->references; + CRYPTO_GET_REF(&b->references, &ref); bio = bio->next_bio; BIO_free(b); /* Since ref count > 1, don't free anyone else. */ @@ -955,8 +951,7 @@ void bio_cleanup(void) CRYPTO_THREAD_lock_free(bio_lookup_lock); bio_lookup_lock = NULL; #endif - CRYPTO_THREAD_lock_free(bio_type_lock); - bio_type_lock = NULL; + CRYPTO_FREE_REF(&bio_type_count); } /* Internal variant of the below BIO_wait() not calling ERR_raise(...) */ -- cgit v1.2.3