]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Hoist remaining locks after tests of fr_io_client ht (CIDs below)
authorJames Jones <jejones3141@gmail.com>
Tue, 21 Nov 2023 15:56:51 +0000 (09:56 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 25 Jan 2024 19:51:06 +0000 (13:51 -0600)
CIDS: 155170615517031551699

src/lib/io/master.c

index a51056c10d536460868a189d99422517456833ea..52733d8f4ec7eb68b24c05620e865ba1ad77acfd 100644 (file)
@@ -431,17 +431,17 @@ static int count_connections(UNUSED uint8_t const *key, UNUSED size_t keylen, vo
        fr_io_client_t *client = talloc_get_type_abort(data, fr_io_client_t);
        int connections;
 
-       /*
-        *      This client has no connections, skip the mutex lock.
-        */
-       if (!client->ht) return 0;
+       pthread_mutex_lock(&client->mutex);
 
-       fr_assert(client->use_connected);
+       if (!client->ht) {
+               pthread_mutex_unlock(&client->mutex);
+               return 0;
+       }
 
-       pthread_mutex_lock(&client->mutex);
        connections = fr_hash_table_num_elements(client->ht);
        pthread_mutex_unlock(&client->mutex);
 
+       fr_assert(client->use_connected);
        *((uint32_t *) ctx) += connections;
 
        return 0;
@@ -1992,11 +1992,9 @@ static void client_expiry_timer(fr_event_list_t *el, fr_time_t now, void *uctx)
                if (connection) {
                        fr_io_client_t *parent = connection->parent;
 
-                       if (parent->ht) {
-                               pthread_mutex_lock(&parent->mutex);
-                               (void) fr_hash_table_delete(parent->ht, connection);
-                               pthread_mutex_unlock(&parent->mutex);
-                       }
+                       pthread_mutex_lock(&parent->mutex);
+                       if (parent->ht) (void) fr_hash_table_delete(parent->ht, connection);
+                       pthread_mutex_unlock(&parent->mutex);
 
                        /*
                         *      Mark the connection as dead, and tell
@@ -2606,11 +2604,9 @@ static int mod_close(fr_listen_t *li)
         *      Remove connection from parent hash table
         */
        parent = connection->parent;
-       if (parent->ht) {
-               pthread_mutex_lock(&parent->mutex);
-               (void) fr_hash_table_delete(parent->ht, connection);
-               pthread_mutex_unlock(&parent->mutex);
-       }
+       pthread_mutex_lock(&parent->mutex);
+       if (parent->ht) (void) fr_hash_table_delete(parent->ht, connection);
+       pthread_mutex_unlock(&parent->mutex);
 
        /*
         *      Clean up listener