diff options
author | FdaSilvaYY <fdasilvayy@gmail.com> | 2016-03-07 22:45:58 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-05-16 10:17:33 +0100 |
commit | c5ebfcab713a82a1d46a51c8c2668c419425b387 (patch) | |
tree | ca8da99a90b24c37c37ce417ad02c1f35e1e1735 /ssl/ssl_lib.c | |
parent | 592b6fb489c97be2b039ab671647aa58a472204a (diff) |
Unify <TYPE>_up_ref methods signature and behaviour.
Add a status return value instead of void.
Add some sanity checks on reference counter value.
Update the docs.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'ssl/ssl_lib.c')
-rw-r--r-- | ssl/ssl_lib.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 9d189aa51c..e7eb3028b4 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -774,10 +774,16 @@ SSL *SSL_new(SSL_CTX *ctx) return NULL; } -void SSL_up_ref(SSL *s) +int SSL_up_ref(SSL *s) { int i; - CRYPTO_atomic_add(&s->references, 1, &i, s->lock); + + if (CRYPTO_atomic_add(&s->references, 1, &i, s->lock) <= 0) + return 0; + + REF_PRINT_COUNT("SSL", s); + REF_ASSERT_ISNT(i < 2); + return ((i > 1) ? 1 : 0); } int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx, @@ -2504,10 +2510,16 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) return NULL; } -void SSL_CTX_up_ref(SSL_CTX *ctx) +int SSL_CTX_up_ref(SSL_CTX *ctx) { int i; - CRYPTO_atomic_add(&ctx->references, 1, &i, ctx->lock); + + if (CRYPTO_atomic_add(&ctx->references, 1, &i, ctx->lock) <= 0) + return 0; + + REF_PRINT_COUNT("SSL_CTX", ctx); + REF_ASSERT_ISNT(i < 2); + return ((i > 1) ? 1 : 0); } void SSL_CTX_free(SSL_CTX *a) |