From 728dc1a0f21a68acdc5b02744ca12c9cc9aaae88 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Sat, 30 Jun 2007 15:20:55 +0000 Subject: Avoid overwriting the hash_mutex table for applications that incorrectly calls apr_atomic_init(). Noticied by: Tim Jones PR: 42760 git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@552161 13f79535-47bb-0310-9956-ffa450edef68 --- atomic/unix/apr_atomic.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'atomic') diff --git a/atomic/unix/apr_atomic.c b/atomic/unix/apr_atomic.c index 7aab87870..2bd645e05 100644 --- a/atomic/unix/apr_atomic.c +++ b/atomic/unix/apr_atomic.c @@ -226,12 +226,28 @@ APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, static apr_thread_mutex_t **hash_mutex; #endif /* APR_HAS_THREADS */ +#if APR_HAS_THREADS +static apr_status_t atomic_cleanup(void *data) +{ + if (hash_mutex == data) + hash_mutex = NULL; + + return APR_SUCCESS; +} +#endif + apr_status_t apr_atomic_init(apr_pool_t *p) { #if APR_HAS_THREADS int i; apr_status_t rv; + + if (hash_mutex != NULL) + return APR_SUCCESS; + hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) * NUM_ATOMIC_HASH); + apr_pool_cleanup_register(p, hash_mutex, atomic_cleanup, + apr_pool_cleanup_null); for (i = 0; i < NUM_ATOMIC_HASH; i++) { rv = apr_thread_mutex_create(&(hash_mutex[i]), -- cgit v1.2.1