mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 21:23:06 +00:00
Add minimal initialized TSD.
We use the minimal_initilized tsd (which requires no cleanup) for free() specifically, if tsd hasn't been initialized yet. Any other activity will transit the state from minimal to normal. This is to workaround the case where a thread has no malloc calls in its lifetime until during thread termination, free() happens after tls destructors.
This commit is contained in:
@@ -2264,7 +2264,15 @@ JEMALLOC_EXPORT void JEMALLOC_NOTHROW
|
||||
je_free(void *ptr) {
|
||||
UTRACE(ptr, 0, 0);
|
||||
if (likely(ptr != NULL)) {
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
/*
|
||||
* We avoid setting up tsd fully (e.g. tcache, arena binding)
|
||||
* based on only free() calls -- other activities trigger the
|
||||
* minimal to full transition. This is because free() may
|
||||
* happen during thread shutdown after tls deallocation: if a
|
||||
* thread never had any malloc activities until then, a
|
||||
* fully-setup tsd won't be destructed properly.
|
||||
*/
|
||||
tsd_t *tsd = tsd_fetch_min();
|
||||
check_entry_exit_locking(tsd_tsdn(tsd));
|
||||
|
||||
tcache_t *tcache;
|
||||
|
||||
Reference in New Issue
Block a user