From 909fda640a31a4774cfaefe59eedbf7fc1608afc Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 30 Jan 2011 13:44:11 -0800 Subject: [PATCH] libc - Fix bogus pthread_getspecific() return value due to bug in nmalloc * 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 --- lib/libc/stdlib/nmalloc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/libc/stdlib/nmalloc.c b/lib/libc/stdlib/nmalloc.c index 4ce6f01..6c98d90 100644 --- a/lib/libc/stdlib/nmalloc.c +++ b/lib/libc/stdlib/nmalloc.c @@ -418,11 +418,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; } -- 1.7.7.2