summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2016-01-30 12:04:25 -0500
committerRich Salz <rsalz@openssl.org>2016-02-11 12:40:32 -0500
commitf3f1cf8444f439c0be9de04bf3821a20d00fd956 (patch)
tree50d0fc624d4680e6cd734328126cd60a9dc128be /crypto
parent7823d792d0cad3b44ad5389a8d3381becefe7f44 (diff)
Move to REF_DEBUG, for consistency.
Add utility macros REF_ASSERT_NOT and REF_PRINT_COUNT This is also RT 4181 Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/asn1/tasn_utl.c7
-rw-r--r--crypto/asn1/x_info.c11
-rw-r--r--crypto/asn1/x_pkey.c11
-rw-r--r--crypto/bio/bio_err.c2
-rw-r--r--crypto/bio/bio_lib.c11
-rw-r--r--crypto/dh/dh_lib.c23
-rw-r--r--crypto/dsa/dsa_lib.c23
-rw-r--r--crypto/dso/dso_lib.c11
-rw-r--r--crypto/ec/ec_key.c23
-rw-r--r--crypto/engine/eng_init.c7
-rw-r--r--crypto/engine/eng_lib.c7
-rw-r--r--crypto/err/err.c25
-rw-r--r--crypto/evp/p_lib.c11
-rw-r--r--crypto/lock.c2
-rw-r--r--crypto/rsa/rsa_lib.c23
-rw-r--r--crypto/x509/x509_lu.c11
16 files changed, 50 insertions, 158 deletions
diff --git a/crypto/asn1/tasn_utl.c b/crypto/asn1/tasn_utl.c
index f1807c20f4..51f22aa7c6 100644
--- a/crypto/asn1/tasn_utl.c
+++ b/crypto/asn1/tasn_utl.c
@@ -118,12 +118,9 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
}
ret = CRYPTO_add(lck, op, aux->ref_lock);
#ifdef REF_PRINT
- fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck);
-#endif
-#ifdef REF_CHECK
- if (ret < 0)
- fprintf(stderr, "%s, bad reference count\n", it->sname);
+ fprintf(stderr, "%p:%4d:%s\n", it, *lck, it->sname);
#endif
+ REF_ASSERT_ISNT(ret < 0);
return ret;
}
diff --git a/crypto/asn1/x_info.c b/crypto/asn1/x_info.c
index 375e0ae8bd..adee224699 100644
--- a/crypto/asn1/x_info.c
+++ b/crypto/asn1/x_info.c
@@ -82,17 +82,10 @@ void X509_INFO_free(X509_INFO *x)
return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO);
-#ifdef REF_PRINT
- REF_PRINT("X509_INFO", x);
-#endif
+ REF_PRINT_COUNT("X509_INFO", x);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "X509_INFO_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
X509_free(x->x509);
X509_CRL_free(x->crl);
diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c
index 5bca68ad1e..6e09d29239 100644
--- a/crypto/asn1/x_pkey.c
+++ b/crypto/asn1/x_pkey.c
@@ -90,17 +90,10 @@ void X509_PKEY_free(X509_PKEY *x)
return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_PKEY);
-#ifdef REF_PRINT
- REF_PRINT("X509_PKEY", x);
-#endif
+ REF_PRINT_COUNT("X509_PKEY", x);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "X509_PKEY_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
X509_ALGOR_free(x->enc_algor);
ASN1_OCTET_STRING_free(x->enc_pkey);
diff --git a/crypto/bio/bio_err.c b/crypto/bio/bio_err.c
index 5b2eb952f8..36b9dfe62c 100644
--- a/crypto/bio/bio_err.c
+++ b/crypto/bio/bio_err.c
@@ -1,3 +1,4 @@
+/* crypto/bio/bio_err.c */
/* ====================================================================
* Copyright (c) 1999-2016 The OpenSSL Project. All rights reserved.
*
@@ -96,6 +97,7 @@ static ERR_STRING_DATA BIO_str_functs[] = {
{ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
{ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
{ERR_FUNC(BIO_F_BIO_SOCKET), "BIO_socket"},
+ {ERR_FUNC(BIO_F_BIO_SOCKET_NBIO), "BIO_socket_nbio"},
{ERR_FUNC(BIO_F_BIO_SOCK_INFO), "BIO_sock_info"},
{ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
{ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
index ef68dbb774..ee8d622b20 100644
--- a/crypto/bio/bio_lib.c
+++ b/crypto/bio/bio_lib.c
@@ -110,17 +110,10 @@ int BIO_free(BIO *a)
return (0);
i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);
-#ifdef REF_PRINT
- REF_PRINT("BIO", a);
-#endif
+ REF_PRINT_COUNT("BIO", a);
if (i > 0)
return (1);
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "BIO_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
if ((a->callback != NULL) &&
((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))
return (i);
diff --git a/crypto/dh/dh_lib.c b/crypto/dh/dh_lib.c
index 013008eafe..9167d69ea8 100644
--- a/crypto/dh/dh_lib.c
+++ b/crypto/dh/dh_lib.c
@@ -157,17 +157,10 @@ void DH_free(DH *r)
if (r == NULL)
return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
-#ifdef REF_PRINT
- REF_PRINT("DH", r);
-#endif
+ REF_PRINT_COUNT("DH", r);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "DH_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
if (r->meth->finish)
r->meth->finish(r);
@@ -192,15 +185,9 @@ void DH_free(DH *r)
int DH_up_ref(DH *r)
{
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DH);
-#ifdef REF_PRINT
- REF_PRINT("DH", r);
-#endif
-#ifdef REF_CHECK
- if (i < 2) {
- fprintf(stderr, "DH_up, bad reference count\n");
- abort();
- }
-#endif
+
+ REF_PRINT_COUNT("DH", r);
+ REF_ASSERT_ISNT(i < 2);
return ((i > 1) ? 1 : 0);
}
diff --git a/crypto/dsa/dsa_lib.c b/crypto/dsa/dsa_lib.c
index b8d8e10ddb..26a5d28f0d 100644
--- a/crypto/dsa/dsa_lib.c
+++ b/crypto/dsa/dsa_lib.c
@@ -165,17 +165,10 @@ void DSA_free(DSA *r)
return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA);
-#ifdef REF_PRINT
- REF_PRINT("DSA", r);
-#endif
+ REF_PRINT_COUNT("DSA", r);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "DSA_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
if (r->meth->finish)
r->meth->finish(r);
@@ -199,15 +192,9 @@ void DSA_free(DSA *r)
int DSA_up_ref(DSA *r)
{
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA);
-#ifdef REF_PRINT
- REF_PRINT("DSA", r);
-#endif
-#ifdef REF_CHECK
- if (i < 2) {
- fprintf(stderr, "DSA_up_ref, bad reference count\n");
- abort();
- }
-#endif
+
+ REF_PRINT_COUNT("DSA", r);
+ REF_ASSERT_ISNT(i < 2);
return ((i > 1) ? 1 : 0);
}
diff --git a/crypto/dso/dso_lib.c b/crypto/dso/dso_lib.c
index bc3a785940..0921fb2409 100644
--- a/crypto/dso/dso_lib.c
+++ b/crypto/dso/dso_lib.c
@@ -136,17 +136,10 @@ int DSO_free(DSO *dso)
return (1);
i = CRYPTO_add(&dso->references, -1, CRYPTO_LOCK_DSO);
-#ifdef REF_PRINT
- REF_PRINT("DSO", dso);
-#endif
+ REF_PRINT_COUNT("DSO", dso);
if (i > 0)
return (1);
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "DSO_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED);
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index 57388da91e..7d8507ca50 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -99,17 +99,10 @@ void EC_KEY_free(EC_KEY *r)
return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC);
-#ifdef REF_PRINT
- REF_PRINT("EC_KEY", r);
-#endif
+ REF_PRINT_COUNT("EC_KEY", r);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "EC_KEY_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
if (r->meth->finish != NULL)
r->meth->finish(r);
@@ -213,15 +206,9 @@ EC_KEY *EC_KEY_dup(EC_KEY *ec_key)
int EC_KEY_up_ref(EC_KEY *r)
{
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC);
-#ifdef REF_PRINT
- REF_PRINT("EC_KEY", r);
-#endif
-#ifdef REF_CHECK
- if (i < 2) {
- fprintf(stderr, "EC_KEY_up, bad reference count\n");
- abort();
- }
-#endif
+
+ REF_PRINT_COUNT("EC_KEY", r);
+ REF_ASSERT_ISNT(i < 2);
return ((i > 1) ? 1 : 0);
}
diff --git a/crypto/engine/eng_init.c b/crypto/engine/eng_init.c
index c5f3805765..b66d476d80 100644
--- a/crypto/engine/eng_init.c
+++ b/crypto/engine/eng_init.c
@@ -108,12 +108,7 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
if (!to_return)
return 0;
}
-#ifdef REF_CHECK
- if (e->funct_ref < 0) {
- fprintf(stderr, "ENGINE_finish, bad functional reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(e->funct_ref < 0);
/* Release the structural reference too */
if (!engine_free_util(e, 0)) {
ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, ENGINE_R_FINISH_FAILED);
diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
index 388e8ca877..15c2c6ff68 100644
--- a/crypto/engine/eng_lib.c
+++ b/crypto/engine/eng_lib.c
@@ -114,12 +114,7 @@ int engine_free_util(ENGINE *e, int locked)
engine_ref_debug(e, 0, -1)
if (i > 0)
return 1;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "ENGINE_free, bad structural reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
/* Free up any dynamically allocated public key methods */
engine_pkey_meths_free(e);
engine_pkey_asn1_meths_free(e);
diff --git a/crypto/err/err.c b/crypto/err/err.c
index 5e1d5c55b4..00565fa473 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -241,9 +241,13 @@ static void int_thread_del_item(const ERR_STATE *);
/*
* The internal state
*/
+
+/* This is a struct so that REF_PRINT_COUNT works. */
+static struct refcount {
+ int references;
+} refcount = { 0 };
static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL;
static LHASH_OF(ERR_STATE) *int_thread_hash = NULL;
-static int int_thread_hash_references = 0;
static int int_err_library_number = ERR_LIB_USER;
static unsigned long get_error_values(int inc, int top, const char **file,
@@ -317,7 +321,7 @@ static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit)
int_thread_hash = lh_ERR_STATE_new(err_state_hash, err_state_cmp);
}
if (int_thread_hash != NULL) {
- int_thread_hash_references++;
+ refcount.references++;
ret = int_thread_hash;
}
if (lockit)
@@ -332,19 +336,12 @@ static void int_thread_release(LHASH_OF(ERR_STATE) **hash)
if (hash == NULL || *hash == NULL)
return;
- i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR);
+ i = CRYPTO_add(&refcount.references, -1, CRYPTO_LOCK_ERR);
-#ifdef REF_PRINT
- fprintf(stderr, "%4d:%s\n", int_thread_hash_references, "ERR");
-#endif
+ REF_PRINT_COUNT(&refcount, "ERR");
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "int_thread_release, bad reference count\n");
- abort(); /* ok */
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
*hash = NULL;
}
@@ -389,10 +386,10 @@ static void int_thread_del_item(const ERR_STATE *d)
p = lh_ERR_STATE_delete(hash, d);
/* If there are no other references, and we just removed the
* last item, delete the int_thread_hash */
- if (int_thread_hash_references == 1
+ if (refcount.references == 1
&& int_thread_hash
&& lh_ERR_STATE_num_items(int_thread_hash) == 0) {
- int_thread_hash_references = 0;
+ refcount.references = 0;
lh_ERR_STATE_free(int_thread_hash);
int_thread_hash = NULL;
hash = NULL;
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c
index 0626c27e15..1f9f6f010f 100644
--- a/crypto/evp/p_lib.c
+++ b/crypto/evp/p_lib.c
@@ -425,17 +425,10 @@ void EVP_PKEY_free(EVP_PKEY *x)
return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);
-#ifdef REF_PRINT
- REF_PRINT("EVP_PKEY", x);
-#endif
+ REF_PRINT_COUNT("EVP_PKEY", x);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "EVP_PKEY_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
EVP_PKEY_free_it(x);
sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
OPENSSL_free(x);
diff --git a/crypto/lock.c b/crypto/lock.c
index 0925214f32..9be78c4ed8 100644
--- a/crypto/lock.c
+++ b/crypto/lock.c
@@ -305,7 +305,7 @@ void CRYPTO_destroy_dynlockid(int i)
pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
if (pointer != NULL) {
--pointer->references;
-#ifdef REF_CHECK
+#ifdef REF_DEBUG
if (pointer->references < 0) {
OPENSSL_showfatal("CRYPTO_destroy_dynlockid, bad reference count\n");
abort();
diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c
index 62b2854ecc..a8afb2cef7 100644
--- a/crypto/rsa/rsa_lib.c
+++ b/crypto/rsa/rsa_lib.c
@@ -183,17 +183,10 @@ void RSA_free(RSA *r)
return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_RSA);
-#ifdef REF_PRINT
- REF_PRINT("RSA", r);
-#endif
+ REF_PRINT_COUNT("RSA", r);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "RSA_free, bad reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
if (r->meth->finish)
r->meth->finish(r);
@@ -221,15 +214,9 @@ void RSA_free(RSA *r)
int RSA_up_ref(RSA *r)
{
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
-#ifdef REF_PRINT
- REF_PRINT("RSA", r);
-#endif
-#ifdef REF_CHECK
- if (i < 2) {
- fprintf(stderr, "RSA_up_ref, bad reference count\n");
- abort();
- }
-#endif
+
+ REF_PRINT_COUNT("RSA", r);
+ REF_ASSERT_ISNT(i < 2);
return ((i > 1) ? 1 : 0);
}
diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c
index cd84394141..b53ec48032 100644
--- a/crypto/x509/x509_lu.c
+++ b/crypto/x509/x509_lu.c
@@ -229,17 +229,10 @@ void X509_STORE_free(X509_STORE *vfy)
return;
i = CRYPTO_add(&vfy->references, -1, CRYPTO_LOCK_X509_STORE);
-#ifdef REF_PRINT
- REF_PRINT("X509_STORE", vfy);
-#endif
+ REF_PRINT_COUNT("X509_STORE", vfy);
if (i > 0)
return;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "X509_STORE_free, bad reference count\n");
- abort(); /* ok */
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
sk = vfy->get_cert_methods;
for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) {