From: James Jones Date: Tue, 21 Nov 2023 15:56:51 +0000 (-0600) Subject: Hoist remaining locks after tests of fr_io_client ht (CIDs below) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5c9632735c95eba80a7b044c4163594df057e00;p=thirdparty%2Ffreeradius-server.git Hoist remaining locks after tests of fr_io_client ht (CIDs below) CIDS: 1551706, 1551703, 1551699 --- diff --git a/src/lib/io/master.c b/src/lib/io/master.c index a51056c10d5..52733d8f4ec 100644 --- a/src/lib/io/master.c +++ b/src/lib/io/master.c @@ -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