]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Hoist mutex lock above check of client->ht (CID #1551708)
authorJames Jones <jejones3141@gmail.com>
Mon, 20 Nov 2023 21:24:08 +0000 (15:24 -0600)
committerAlan DeKok <aland@freeradius.org>
Tue, 21 Nov 2023 12:46:26 +0000 (07:46 -0500)
Other checks of client->ht are so guarded.

src/lib/io/master.c

index caaef884fa3ee3731ddc894ed113a0ae55f8ff1c..bff1ef11b5e79d27d01628c60301d517e1637e06 100644 (file)
@@ -785,20 +785,21 @@ static fr_io_connection_t *fr_io_connection_alloc(fr_io_instance_t const *inst,
         *      Add the connection to the set of connections for this
         *      client.
         */
+       pthread_mutex_lock(&client->mutex);
        if (client->ht) {
-               pthread_mutex_lock(&client->mutex);
                if (nak) (void) fr_hash_table_delete(client->ht, nak);
                ret = fr_hash_table_insert(client->ht, connection);
                client->ready_to_delete = false;
-               pthread_mutex_unlock(&client->mutex);
 
                if (!ret) {
+                       pthread_mutex_unlock(&client->mutex);
                        ERROR("proto_%s - Failed inserting connection into tracking table.  "
                              "Closing it, and discarding all packets for connection %s.",
                              inst->app_io->common.name, connection->name);
                        goto cleanup;
                }
        }
+       pthread_mutex_unlock(&client->mutex);
 
        /*
         *      It's a NAK client.  Set the state to NAK, and don't