Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 85358 invoked by uid 500); 30 May 2002 00:36:43 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 85335 invoked from network); 30 May 2002 00:36:43 -0000 Date: 30 May 2002 00:36:42 -0000 Message-ID: <20020530003642.45843.qmail@icarus.apache.org> From: striker@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/memory/unix apr_pools.c X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N striker 02/05/29 17:36:42 Modified: memory/unix apr_pools.c Log: Fix the pool debug code. A pool clear destroys the pools mutex. Make sure no other code uses the pools mutex while it is invalid. Tested by: Philip Martin Revision Changes Path 1.172 +31 -0 apr/memory/unix/apr_pools.c Index: apr_pools.c =================================================================== RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v retrieving revision 1.171 retrieving revision 1.172 diff -u -r1.171 -r1.172 --- apr_pools.c 30 May 2002 00:20:56 -0000 1.171 +++ apr_pools.c 30 May 2002 00:36:42 -0000 1.172 @@ -1382,13 +1382,44 @@ APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *pool, const char *file_line) { +#if APR_HAS_THREADS + apr_thread_mutex_t *mutex = NULL; +#endif + apr_pool_check_integrity(pool); #if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) apr_pool_log_event(pool, "CLEAR", file_line, 1); #endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */ +#if APR_HAS_THREADS + if (pool->parent != NULL) + mutex = pool->parent->mutex; + + /* Lock the parent mutex before clearing so that if we have our + * own mutex it won't be accessed by apr_pool_walk_tree after + * it has been destroyed. + */ + if (mutex != NULL && mutex != pool->mutex) { + apr_thread_mutex_lock(mutex); + } +#endif + pool_clear_debug(pool, file_line); + +#if APR_HAS_THREADS + /* If we had our own mutex, it will have been destroyed by + * the registered cleanups. Recreate the mutex. Unlock + * the mutex we obtained above. + */ + if (mutex != pool->mutex) { + (void)apr_thread_mutex_create(&pool->mutex, + APR_THREAD_MUTEX_NESTED, pool); + + if (mutex != NULL) + (void)apr_thread_mutex_unlock(mutex); + } +#endif /* APR_HAS_THREADS */ } APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *pool,