Skip to content

Commit 64d9ada

Browse files
pks-tgitster
authored andcommitted
trace2: destroy context stored in thread-local storage
Each thread may have a specific context in the trace2 subsystem that we set up via thread-local storage. We do not set up a destructor for this data though, which means that the context data will leak. Plug this leak by installing a destructor. This leak is exposed by t7814, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f795a1 commit 64d9ada

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

trace2/tr2_tls.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,19 @@ uint64_t tr2tls_absolute_elapsed(uint64_t us)
152152
return us - tr2tls_us_start_process;
153153
}
154154

155+
static void tr2tls_key_destructor(void *payload)
156+
{
157+
struct tr2tls_thread_ctx *ctx = payload;
158+
free((char *)ctx->thread_name);
159+
free(ctx->array_us_start);
160+
free(ctx);
161+
}
162+
155163
void tr2tls_init(void)
156164
{
157165
tr2tls_start_process_clock();
158166

159-
pthread_key_create(&tr2tls_key, NULL);
167+
pthread_key_create(&tr2tls_key, tr2tls_key_destructor);
160168
init_recursive_mutex(&tr2tls_mutex);
161169

162170
tr2tls_thread_main =

0 commit comments

Comments
 (0)