pullup from trunk
authorAlexandra Ellwood <lxs@mit.edu>
Mon, 21 Mar 2005 19:59:29 +0000 (19:59 +0000)
committerAlexandra Ellwood <lxs@mit.edu>
Mon, 21 Mar 2005 19:59:29 +0000 (19:59 +0000)
ticket: 2971

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@17130 dc483132-0cff-0310-8789-dd5450dbe970

src/util/support/ChangeLog
src/util/support/threads.c

index 5db19b86ee0fb62bb35d62791bc4a9c532f3b51c..ae56c70947d2d54a566d837130d35cdb1e80ae96 100644 (file)
@@ -1,3 +1,11 @@
+2005-03-20  Alexandra Ellwood  <lxs@mit.edu>
+
+       * threads.c (thread_termination): Free array of pointers
+       to thread-specific data (t) on thread termination.  Use
+       existing mutex to prevent the deletion of the array from
+       interfering with the global list of thread specific data
+       (used for library termination).
+
 2004-12-15  Jeffrey Altman <jaltman@mit.edu>
 
         * Makefile.in: rename krb5support_32.dll to k5sprt32.dll
index eb27f1cf9771d0d35da0e9cc0097c781618993c2..4e6bbfc8de3a9354b8258cfb222ad51c73f1f6da 100644 (file)
@@ -117,30 +117,36 @@ static void thread_termination(void *);
 
 static void thread_termination (void *tptr)
 {
-    int i, pass, none_found;
-    struct tsd_block *t = tptr;
-
-    /* Make multiple passes in case, for example, a libkrb5 cleanup
-       function wants to print out an error message, which causes
-       com_err to allocate a thread-specific buffer, after we just
-       freed up the old one.
-
-       Shouldn't actually happen, if we're careful, but check just in
-       case.  */
-
-    pass = 0;
-    none_found = 0;
-    while (pass < 4 && !none_found) {
-       none_found = 1;
-       for (i = 0; i < K5_KEY_MAX; i++) {
-           if (destructors_set[i] && destructors[i] && t->values[i]) {
-               void *v = t->values[i];
-               t->values[i] = 0;
-               (*destructors[i])(v);
-               none_found = 0;
-           }
-       }
-    }
+    int err = k5_mutex_lock(&key_lock);
+    if (err == 0) {
+        int i, pass, none_found;
+        struct tsd_block *t = tptr;
+        
+        /* Make multiple passes in case, for example, a libkrb5 cleanup
+            function wants to print out an error message, which causes
+            com_err to allocate a thread-specific buffer, after we just
+            freed up the old one.
+            
+            Shouldn't actually happen, if we're careful, but check just in
+            case.  */
+        
+        pass = 0;
+        none_found = 0;
+        while (pass < 4 && !none_found) {
+            none_found = 1;
+            for (i = 0; i < K5_KEY_MAX; i++) {
+                if (destructors_set[i] && destructors[i] && t->values[i]) {
+                    void *v = t->values[i];
+                    t->values[i] = 0;
+                    (*destructors[i])(v);
+                    none_found = 0;
+                }
+            }
+        }
+        free (t);
+        err = k5_mutex_unlock(&key_lock);
+   }
+    
     /* remove thread from global linked list */
 }