From 0b5e3908cfd127a22845db6581a998311e0027ee Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Fri, 15 May 2015 13:08:38 -0700 Subject: [PATCH] Convert reference counts in ssl/ Convert reference counts in ssl/ to use |CRYPTO_refcount_t|. Change-Id: I5d60f641b0c89b1ddfe38bfbd9d7285c60377f4c Reviewed-on: https://boringssl-review.googlesource.com/4773 Reviewed-by: Adam Langley --- include/openssl/ssl.h | 8 +++----- ssl/ssl_lib.c | 8 ++++---- ssl/ssl_sess.c | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h index 48b3fc02..6d1c29e7 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h @@ -150,15 +150,13 @@ #include #include #include +#include #include #if !defined(OPENSSL_WINDOWS) #include #endif -/* Some code expected to get the threading functions by including ssl.h. */ -#include - /* wpa_supplicant expects to get the version functions from ssl.h */ #include @@ -414,7 +412,7 @@ struct ssl_session_st { * not ok, we must remember the error for session reuse: */ long verify_result; /* only for servers */ - int references; + CRYPTO_refcount_t references; long timeout; long time; @@ -849,7 +847,7 @@ struct ssl_ctx_st { SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, uint8_t *data, int len, int *copy); - int references; + CRYPTO_refcount_t references; /* if defined, these override the X509_verify_cert() calls */ int (*app_verify_callback)(X509_STORE_CTX *, void *); diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 068bc630..c4f4a29d 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -293,10 +293,10 @@ SSL *SSL_new(SSL_CTX *ctx) { s->quiet_shutdown = ctx->quiet_shutdown; s->max_send_fragment = ctx->max_send_fragment; - CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX); + CRYPTO_refcount_inc(&ctx->references); s->ctx = ctx; s->tlsext_ticket_expected = 0; - CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX); + CRYPTO_refcount_inc(&ctx->references); s->initial_ctx = ctx; if (ctx->tlsext_ecpointformatlist) { s->tlsext_ecpointformatlist = BUF_memdup( @@ -1758,7 +1758,7 @@ err2: void SSL_CTX_free(SSL_CTX *ctx) { if (ctx == NULL || - CRYPTO_add(&ctx->references, -1, CRYPTO_LOCK_SSL_CTX) > 0) { + !CRYPTO_refcount_dec_and_test_zero(&ctx->references)) { return; } @@ -2320,7 +2320,7 @@ SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx) { ssl_cert_free(ssl->cert); ssl->cert = ssl_cert_dup(ctx->cert); - CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX); + CRYPTO_refcount_inc(&ctx->references); SSL_CTX_free(ssl->ctx); /* decrement reference count */ ssl->ctx = ctx; diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c index 3eb428f0..b358b5eb 100644 --- a/ssl/ssl_sess.c +++ b/ssl/ssl_sess.c @@ -607,14 +607,14 @@ static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lock) { SSL_SESSION *SSL_SESSION_up_ref(SSL_SESSION *session) { if (session) { - CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION); + CRYPTO_refcount_inc(&session->references); } return session; } void SSL_SESSION_free(SSL_SESSION *session) { if (session == NULL || - CRYPTO_add(&session->references, -1, CRYPTO_LOCK_SSL_SESSION) > 0) { + !CRYPTO_refcount_dec_and_test_zero(&session->references)) { return; }