Remove get_hash completely
authorRich Salz <rsalz@openssl.org>
Wed, 3 Aug 2016 19:24:57 +0000 (15:24 -0400)
committerRich Salz <rsalz@openssl.org>
Thu, 4 Aug 2016 18:23:08 +0000 (14:23 -0400)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1389)

crypto/err/err.c

index eac2025fd52796ee07070a8825c255de9c2b6a0f..584bb9e10d0002add99aa0c2abe59c8d1c7cb621 100644 (file)
@@ -125,8 +125,6 @@ static CRYPTO_THREAD_LOCAL err_thread_local;
 static CRYPTO_ONCE err_string_init = CRYPTO_ONCE_STATIC_INIT;
 static CRYPTO_RWLOCK *err_string_lock;
 
-/* Predeclarations of the "err_defaults" functions */
-static LHASH_OF(ERR_STRING_DATA) *get_hash(int create);
 static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *);
 
 /*
@@ -155,23 +153,13 @@ static int err_string_data_cmp(const ERR_STRING_DATA *a,
     return (int)(a->error - b->error);
 }
 
-static LHASH_OF(ERR_STRING_DATA) *get_hash(int create)
-{
-    if (int_error_hash == NULL && create)
-        int_error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash,
-                                                err_string_data_cmp);
-    return int_error_hash;
-}
-
 static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
 {
     ERR_STRING_DATA *p = NULL;
-    LHASH_OF(ERR_STRING_DATA) *hash;
 
     CRYPTO_THREAD_read_lock(err_string_lock);
-    hash = get_hash(0);
-    if (hash)
-        p = lh_ERR_STRING_DATA_retrieve(hash, d);
+    if (int_error_hash != NULL)
+        p = lh_ERR_STRING_DATA_retrieve(int_error_hash, d);
     CRYPTO_THREAD_unlock(err_string_lock);
 
     return p;
@@ -290,15 +278,15 @@ int ERR_load_ERR_strings(void)
 
 static void err_load_strings(int lib, ERR_STRING_DATA *str)
 {
-    LHASH_OF(ERR_STRING_DATA) *hash;
-
     CRYPTO_THREAD_write_lock(err_string_lock);
-    hash = get_hash(1);
-    if (hash) {
+    if (int_error_hash == NULL)
+        int_error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash,
+                                                err_string_data_cmp);
+    if (int_error_hash != NULL) {
         for (; str->error; str++) {
             if (lib)
                 str->error |= ERR_PACK(lib, 0, 0);
-            (void)lh_ERR_STRING_DATA_insert(hash, str);
+            (void)lh_ERR_STRING_DATA_insert(int_error_hash, str);
         }
     }
     CRYPTO_THREAD_unlock(err_string_lock);
@@ -314,18 +302,15 @@ int ERR_load_strings(int lib, ERR_STRING_DATA *str)
 
 int ERR_unload_strings(int lib, ERR_STRING_DATA *str)
 {
-    LHASH_OF(ERR_STRING_DATA) *hash;
-
     if (!RUN_ONCE(&err_string_init, do_err_strings_init))
         return 0;
 
     CRYPTO_THREAD_write_lock(err_string_lock);
-    hash = get_hash(0);
-    if (hash) {
+    if (int_error_hash != NULL) {
         for (; str->error; str++) {
             if (lib)
                 str->error |= ERR_PACK(lib, 0, 0);
-            (void)lh_ERR_STRING_DATA_delete(hash, str);
+            (void)lh_ERR_STRING_DATA_delete(int_error_hash, str);
         }
     }
     CRYPTO_THREAD_unlock(err_string_lock);