Commit f99ffceb4b for openssl.org

commit f99ffceb4b0399c1ff738e738de430553c9ffd52
Author: Jakub Zelenka <jakub.zelenka@openssl.foundation>
Date:   Tue May 19 12:02:28 2026 +0200

    Optimize hashtable without rcu freeing

    It is not necessary to flush table for hash tables without rcu.

    This is follow up to https://github.com/openssl/openssl/pull/31163

    Reviewed-by: Neil Horman <nhorman@openssl.org>
    Reviewed-by: Paul Dale <paul.dale@oracle.com>
    Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
    MergeDate: Thu May 21 09:09:36 2026
    (Merged from https://github.com/openssl/openssl/pull/31237)

diff --git a/crypto/hashtable/hashtable.c b/crypto/hashtable/hashtable.c
index 7b3da99c6d..1cce15ed24 100644
--- a/crypto/hashtable/hashtable.c
+++ b/crypto/hashtable/hashtable.c
@@ -368,22 +368,23 @@ void ossl_ht_free(HT *h)
     if (h == NULL)
         return;

-    ossl_ht_write_lock(h);
-    flush_ok = ossl_ht_flush_internal(h);
-    ossl_ht_write_unlock(h);
-    /* Freeing the lock does a final sync for us */
-    if (!h->config.no_rcu) {
+    if (h->config.no_rcu) {
+        free_oldmd(h->md);
+    } else {
+        ossl_ht_write_lock(h);
+        flush_ok = ossl_ht_flush_internal(h);
+        ossl_ht_write_unlock(h);
+        /* Freeing the lock does a final sync for us */
         CRYPTO_THREAD_lock_free(h->atomic_lock);
         ossl_rcu_lock_free(h->lock);
-    }
-    if (flush_ok) {
-        OPENSSL_free(h->md->neighborhood_ptr_to_free);
-        OPENSSL_free(h->md);
-    } else {
-        free_oldmd(h->md);
+        if (flush_ok) {
+            OPENSSL_free(h->md->neighborhood_ptr_to_free);
+            OPENSSL_free(h->md);
+        } else {
+            free_oldmd(h->md);
+        }
     }
     OPENSSL_free(h);
-    return;
 }

 size_t ossl_ht_count(HT *h)