Skip to content

Commit

Permalink
x509: update to structure based atomics
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from openssl/openssl#21260)
  • Loading branch information
paulidale authored and MrE-Fog committed Jul 2, 2023
1 parent 30c8176 commit ed3cc8c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions crypto/x509/x509_lu.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ X509_STORE *X509_STORE_new(void)
ERR_raise(ERR_LIB_X509, ERR_R_CRYPTO_LIB);
goto err;
}
ret->references = 1;

if (!CRYPTO_NEW_REF(&ret->references, 1))
goto err;
return ret;

err:
X509_VERIFY_PARAM_free(ret->param);
sk_X509_OBJECT_free(ret->objs);
sk_X509_LOOKUP_free(ret->get_cert_methods);
CRYPTO_THREAD_lock_free(ret->lock);
OPENSSL_free(ret);
return NULL;
}
Expand All @@ -228,7 +231,7 @@ void X509_STORE_free(X509_STORE *xs)

if (xs == NULL)
return;
CRYPTO_DOWN_REF(&xs->references, &i, xs->lock);
CRYPTO_DOWN_REF(&xs->references, &i);
REF_PRINT_COUNT("X509_STORE", xs);
if (i > 0)
return;
Expand All @@ -246,14 +249,15 @@ void X509_STORE_free(X509_STORE *xs)
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, xs, &xs->ex_data);
X509_VERIFY_PARAM_free(xs->param);
CRYPTO_THREAD_lock_free(xs->lock);
CRYPTO_FREE_REF(&xs->references);
OPENSSL_free(xs);
}

int X509_STORE_up_ref(X509_STORE *xs)
{
int i;

if (CRYPTO_UP_REF(&xs->references, &i, xs->lock) <= 0)
if (CRYPTO_UP_REF(&xs->references, &i) <= 0)
return 0;

REF_PRINT_COUNT("X509_STORE", xs);
Expand Down
2 changes: 1 addition & 1 deletion crypto/x509/x509_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int X509_up_ref(X509 *x)
{
int i;

if (CRYPTO_UP_REF(&x->references, &i, x->lock) <= 0)
if (CRYPTO_UP_REF(&x->references, &i) <= 0)
return 0;

REF_PRINT_COUNT("X509", x);
Expand Down
2 changes: 1 addition & 1 deletion crypto/x509/x509cset.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int X509_CRL_up_ref(X509_CRL *crl)
{
int i;

if (CRYPTO_UP_REF(&crl->references, &i, crl->lock) <= 0)
if (CRYPTO_UP_REF(&crl->references, &i) <= 0)
return 0;

REF_PRINT_COUNT("X509_CRL", crl);
Expand Down

0 comments on commit ed3cc8c

Please sign in to comment.