diff options
author | Pauli <pauli@openssl.org> | 2023-06-22 09:30:52 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-07-01 21:18:25 +1000 |
commit | 420ad86a0e35ddbd65dae7e9458e36223af5f140 (patch) | |
tree | 0e83ef454e0441732111e1eee6845630fdf6a550 | |
parent | aaab365c5afb950b9ffaa2916635a18e0d34fa98 (diff) |
asn1: update to structure based atomics
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21260)
-rw-r--r-- | crypto/asn1/tasn_utl.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/crypto/asn1/tasn_utl.c b/crypto/asn1/tasn_utl.c index be8931cab4..7bd57dc030 100644 --- a/crypto/asn1/tasn_utl.c +++ b/crypto/asn1/tasn_utl.c @@ -59,7 +59,7 @@ int ossl_asn1_set_choice_selector(ASN1_VALUE **pval, int value, /* * Do atomic reference counting. The value 'op' decides what to do. * If it is +1 then the count is incremented. - * If |op| is 0, lock is initialised and count is set to 1. + * If |op| is 0, count is initialised and set to 1. * If |op| is -1, count is decremented and the return value is the current * reference count or 0 if no reference count is active. * It returns -1 on initialisation error. @@ -68,8 +68,8 @@ int ossl_asn1_set_choice_selector(ASN1_VALUE **pval, int value, int ossl_asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) { const ASN1_AUX *aux; - CRYPTO_REF_COUNT *lck; CRYPTO_RWLOCK **lock; + CRYPTO_REF_COUNT *refcnt; int ret = -1; if ((it->itype != ASN1_ITYPE_SEQUENCE) @@ -78,30 +78,34 @@ int ossl_asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) aux = it->funcs; if (aux == NULL || (aux->flags & ASN1_AFLG_REFCOUNT) == 0) return 0; - lck = offset2ptr(*pval, aux->ref_offset); lock = offset2ptr(*pval, aux->ref_lock); + refcnt = offset2ptr(*pval, aux->ref_offset); switch (op) { case 0: - *lck = ret = 1; + if (!CRYPTO_NEW_REF(refcnt, 1)) + return -1; *lock = CRYPTO_THREAD_lock_new(); if (*lock == NULL) { + CRYPTO_FREE_REF(refcnt); ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); return -1; } + ret = 1; break; case 1: - if (!CRYPTO_UP_REF(lck, &ret, *lock)) + if (!CRYPTO_UP_REF(refcnt, &ret)) return -1; break; case -1: - if (!CRYPTO_DOWN_REF(lck, &ret, *lock)) + if (!CRYPTO_DOWN_REF(refcnt, &ret)) return -1; /* failed */ REF_PRINT_EX(it->sname, ret, (void *)it); REF_ASSERT_ISNT(ret < 0); if (ret == 0) { CRYPTO_THREAD_lock_free(*lock); *lock = NULL; + CRYPTO_FREE_REF(refcnt); } break; } |