You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by da...@apache.org on 2007/06/30 17:34:13 UTC

svn commit: r552163 - in /apr/apr/branches/1.2.x: CHANGES atomic/unix/apr_atomic.c

Author: davi
Date: Sat Jun 30 08:34:13 2007
New Revision: 552163

URL: http://svn.apache.org/viewvc?view=rev&rev=552163
Log:
Backport 552161 from trunk:

Avoid overwriting the hash_mutex table for applications that incorrectly calls
apr_atomic_init().

Noticied by: Tim Jones
PR: 42760

Modified:
    apr/apr/branches/1.2.x/CHANGES
    apr/apr/branches/1.2.x/atomic/unix/apr_atomic.c

Modified: apr/apr/branches/1.2.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/CHANGES?view=diff&rev=552163&r1=552162&r2=552163
==============================================================================
--- apr/apr/branches/1.2.x/CHANGES (original)
+++ apr/apr/branches/1.2.x/CHANGES Sat Jun 30 08:34:13 2007
@@ -1,5 +1,8 @@
 Changes for APR 1.2.10
 
+  *) Avoid overwriting the hash_mutex table for applications that
+     incorrectly calls apr_atomic_init().  PR 42760.  [Davi Arnaut]
+
   *) Allow IPv6 connectivity test to fail, avoiding a potentially fatal
      error.  [Davi Arnaut]
 

Modified: apr/apr/branches/1.2.x/atomic/unix/apr_atomic.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/atomic/unix/apr_atomic.c?view=diff&rev=552163&r1=552162&r2=552163
==============================================================================
--- apr/apr/branches/1.2.x/atomic/unix/apr_atomic.c (original)
+++ apr/apr/branches/1.2.x/atomic/unix/apr_atomic.c Sat Jun 30 08:34:13 2007
@@ -171,12 +171,28 @@
 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]),