diff options
author | Qi Wang <interwq@gwu.edu> | 2023-02-10 15:28:22 -0800 |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2023-02-15 17:49:40 -0800 |
commit | 5fd55837bbc400d8cc15152ac2b80b64baa9b68c (patch) | |
tree | 0431cd8b175358ed7817c625156cfcd53be2fae4 | |
parent | 8580c65f81c5252e493da656a448ec3a8571dab7 (diff) | |
download | jemalloc-5fd55837bbc400d8cc15152ac2b80b64baa9b68c.tar.gz |
Fix thread_name updating for heap profiling.
The current thread name reading path updates the name every time, which requires
both alloc and dalloc -- and the temporary NULL value in the middle causes races
where the prof dump read path gets NULLed in the middle.
Minimize the changes in this commit to isolate the bugfix testing; will also
refactor the whole thread name paths later.
-rw-r--r-- | src/prof_data.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/prof_data.c b/src/prof_data.c index f8b19594..56d3dc88 100644 --- a/src/prof_data.c +++ b/src/prof_data.c @@ -451,16 +451,15 @@ prof_thread_name_alloc(tsd_t *tsd, const char *thread_name) { } size = strlen(thread_name) + 1; - if (size == 1) { - return ""; - } - ret = iallocztm(tsd_tsdn(tsd), size, sz_size2index(size), false, NULL, true, arena_get(TSDN_NULL, 0, true), true); if (ret == NULL) { return NULL; } + memcpy(ret, thread_name, size); + ret[size - 1] = '\0'; + return ret; } @@ -493,14 +492,14 @@ prof_thread_name_set_impl(tsd_t *tsd, const char *thread_name) { return EAGAIN; } - if (tdata->thread_name != NULL) { - idalloctm(tsd_tsdn(tsd), tdata->thread_name, NULL, NULL, true, - true); - tdata->thread_name = NULL; - } - if (strlen(s) > 0) { - tdata->thread_name = s; + char *old_thread_name = tdata->thread_name; + tdata->thread_name = s; + if (old_thread_name != NULL) { + idalloctm(tsd_tsdn(tsd), old_thread_name, /* tcache */ NULL, + /* alloc_ctx */ NULL, /* is_internal */ true, + /* slow_path */ true); } + return 0; } |