libc - Fix bogus pthread_getspecific() return value due to bug in nmalloc
authorMatthew Dillon <dillon@apollo.backplane.com>
Sun, 30 Jan 2011 21:44:11 +0000 (13:44 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sun, 30 Jan 2011 21:47:13 +0000 (13:47 -0800)
* nmalloc was calling pthread_set_specific() prior to calling
  pthread_key_create(), causing it to use key 0 which might already
  have been allocated for other purposes.

* Reorder initializations in _nmalloc_thr_init() to solve the problem.

* This also solves certain application crashes (mail/milter-greylist).

Reported-by: Francois Tigeot <ftigeot@wolfpond.org>
lib/libc/stdlib/nmalloc.c

index 030a3f3..7ff3af3 100644 (file)
@@ -433,11 +433,11 @@ _nmalloc_thr_init(void)
        tp = &thread_mags;
        tp->init = -1;
 
-       pthread_setspecific(thread_mags_key, tp);
        if (mtmagazine_free_live == 0) {
                mtmagazine_free_live = 1;
                pthread_once(&thread_mags_once, mtmagazine_init);
        }
+       pthread_setspecific(thread_mags_key, tp);
        tp->init = 1;
 }