diff options
author | Jason Evans <je@fb.com> | 2011-02-14 02:11:54 (GMT) |
---|---|---|
committer | Jason Evans <je@fb.com> | 2011-02-14 02:11:54 (GMT) |
commit | 9dcad2dfd11762ea3b542ef45a20bd8297c6f18c (patch) | |
tree | f2ce6dda64a1c952aa79e891ad8a6f0d632e7967 /jemalloc/src | |
parent | 6369286f83e800de8753732031289fd6393027e7 (diff) | |
download | jemalloc-9dcad2dfd11762ea3b542ef45a20bd8297c6f18c.zip jemalloc-9dcad2dfd11762ea3b542ef45a20bd8297c6f18c.tar.gz jemalloc-9dcad2dfd11762ea3b542ef45a20bd8297c6f18c.tar.bz2 |
Fix "thread.{de,}allocatedp" mallctl.
For the non-TLS case (as on OS X), if the "thread.{de,}allocatedp"
mallctl was called before any allocation occurred for that thread, the
TSD was still NULL, thus putting the application at risk of
dereferencing NULL. Fix this by refactoring the initialization code,
and making it part of the conditional logic for all per thread
allocation counter accesses.
Diffstat (limited to 'jemalloc/src')
-rw-r--r-- | jemalloc/src/ctl.c | 4 | ||||
-rw-r--r-- | jemalloc/src/jemalloc.c | 22 |
2 files changed, 24 insertions, 2 deletions
diff --git a/jemalloc/src/ctl.c b/jemalloc/src/ctl.c index 0b8b06f..c37b4e7 100644 --- a/jemalloc/src/ctl.c +++ b/jemalloc/src/ctl.c @@ -1151,9 +1151,9 @@ RETURN: #ifdef JEMALLOC_STATS CTL_RO_NL_GEN(thread_allocated, ALLOCATED_GET(), uint64_t); -CTL_RO_NL_GEN(thread_allocatedp, &ALLOCATED_GET(), uint64_t *); +CTL_RO_NL_GEN(thread_allocatedp, ALLOCATEDP_GET(), uint64_t *); CTL_RO_NL_GEN(thread_deallocated, DEALLOCATED_GET(), uint64_t); -CTL_RO_NL_GEN(thread_deallocatedp, &DEALLOCATED_GET(), uint64_t *); +CTL_RO_NL_GEN(thread_deallocatedp, DEALLOCATEDP_GET(), uint64_t *); #endif /******************************************************************************/ diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c index f5434c7..61a36c7 100644 --- a/jemalloc/src/jemalloc.c +++ b/jemalloc/src/jemalloc.c @@ -213,6 +213,28 @@ stats_print_atexit(void) JEMALLOC_P(malloc_stats_print)(NULL, NULL, NULL); } +#if (defined(JEMALLOC_STATS) && defined(NO_TLS)) +thread_allocated_t * +thread_allocated_get_hard(void) +{ + thread_allocated_t *thread_allocated = (thread_allocated_t *) + imalloc(sizeof(thread_allocated_t)); + if (thread_allocated == NULL) { + static thread_allocated_t static_thread_allocated = {0, 0}; + malloc_write("<jemalloc>: Error allocating TSD;" + " mallctl(\"thread.{de,}allocated[p]\", ...)" + " will be inaccurate\n"); + if (opt_abort) + abort(); + return (&static_thread_allocated); + } + pthread_setspecific(thread_allocated_tsd, thread_allocated); + thread_allocated->allocated = 0; + thread_allocated->deallocated = 0; + return (thread_allocated); +} +#endif + /* * End miscellaneous support functions. */ |