summaryrefslogtreecommitdiffstats
path: root/crypto/err
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/err
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/err')
-rw-r--r--crypto/err/err.c25
1 files changed, 11 insertions, 14 deletions
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;