From 7e0668d1e4f78a0c7ff8689b197e2c104ce569e4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 23 Nov 2015 11:11:59 +0100 Subject: [SERVER] Fix race condition potentially leading to use after release --- src/server/altservers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/server/altservers.c') diff --git a/src/server/altservers.c b/src/server/altservers.c index 8eb07ec..7a2aaf7 100644 --- a/src/server/altservers.c +++ b/src/server/altservers.c @@ -379,9 +379,9 @@ static void *altservers_main(void *data UNUSED) } // Work your way through the queue for (itLink = 0; itLink < SERVER_MAX_PENDING_ALT_CHECKS; ++itLink) { - dnbd3_connection_t * const uplink = pending[itLink]; - if ( uplink == NULL ) continue; // Check once before locking, as a mutex is expensive + if ( pending[itLink] == NULL ) continue; // Check once before locking, as a mutex is expensive pthread_mutex_lock( &pendingLockConsume ); + dnbd3_connection_t * const uplink = pending[itLink]; if ( uplink == NULL ) { // Check again after locking pthread_mutex_unlock( &pendingLockConsume ); continue; -- cgit v1.2.3-55-g7522