Merged thread-specific cleanup patch from FreeBSD.
authorAycan iRiCAN <iricanaycan@gmail.com>
Tue, 13 Mar 2012 20:48:27 +0000 (22:48 +0200)
committerSascha Wildner <saw@online.de>
Tue, 13 Mar 2012 19:39:04 +0000 (20:39 +0100)
  See: http://lists.freebsd.org/pipermail/freebsd-threads/2009-June/004563.html

lib/libthread_xu/thread/thr_spec.c

index 8aaf8ef..ae231d6 100644 (file)
@@ -126,10 +126,19 @@ _thread_cleanupspecific(void)
                                }
                                curthread->specific[key].data = NULL;
                                curthread->specific_data_count--;
+                       } else if (curthread->specific[key].data != NULL) {
+                               /* 
+                                * This can happen if the key is deleted via
+                                * pthread_key_delete without first setting the value
+                                * to NULL in all threads. POSIX says that the
+                                * destructor is not invoked in this case.
+                                */
+                               curthread->specific[key].data = NULL;
+                               curthread->specific_data_count--;
                        }
 
                        /*
-                        * If there is a destructore, call it
+                        * If there is a destructor, call it
                         * with the key table entry unlocked:
                         */
                        if (destructor != NULL) {