From 5e5b467e8c8abda496b7896241a46b05256cd22c Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 16 Mar 2005 01:56:17 +0000 Subject: [PATCH] 1833. [bug] Race condition in isc_mutex_lock_profile(). [RT #13660] --- CHANGES | 2 ++ lib/isc/pthreads/mutex.c | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGES b/CHANGES index e839651d5b..8fd37aedc3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +1833. [bug] Race condition in isc_mutex_lock_profile(). [RT #13660] + 1832. [bug] named fails to return BADKEY on unknown TSIG algorithm. [RT #13620] diff --git a/lib/isc/pthreads/mutex.c b/lib/isc/pthreads/mutex.c index d115dc7d85..9842643df5 100644 --- a/lib/isc/pthreads/mutex.c +++ b/lib/isc/pthreads/mutex.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: mutex.c,v 1.8 2004/03/05 05:11:16 marka Exp $ */ +/* $Id: mutex.c,v 1.9 2005/03/16 01:56:17 marka Exp $ */ #include @@ -126,19 +126,6 @@ isc_mutex_lock_profile(isc_mutex_t *mp, const char *file, int line) { isc_mutexlocker_t *locker = NULL; int i; - for (i = 0; i < ISC_MUTEX_MAX_LOCKERS; i++) { - if (mp->stats->lockers[i].file == NULL) { - locker = &mp->stats->lockers[i]; - locker->file = file; - locker->line = line; - break; - } else if (mp->stats->lockers[i].file == file && - mp->stats->lockers[i].line == line) { - locker = &mp->stats->lockers[i]; - break; - } - } - gettimeofday(&prelock_t, NULL); if (pthread_mutex_lock(&mp->mutex) != 0) @@ -152,6 +139,19 @@ isc_mutex_lock_profile(isc_mutex_t *mp, const char *file, int line) { mp->stats->count++; timevaladd(&mp->stats->wait_total, &postlock_t); + for (i = 0; i < ISC_MUTEX_MAX_LOCKERS; i++) { + if (mp->stats->lockers[i].file == NULL) { + locker = &mp->stats->lockers[i]; + locker->file = file; + locker->line = line; + break; + } else if (mp->stats->lockers[i].file == file && + mp->stats->lockers[i].line == line) { + locker = &mp->stats->lockers[i]; + break; + } + } + if (locker != NULL) { locker->count++; timevaladd(&locker->wait_total, &postlock_t);