Skip to content

Commit 8623e10

Browse files
committed
Zero-initialize pthread struct only in debug builds. NFC
1 parent 00f352d commit 8623e10

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

system/lib/pthread/pthread_create.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,20 @@ void _emscripten_thread_free_data(pthread_t t) {
279279
emscripten_builtin_free(t->profilerBlock);
280280
}
281281
#endif
282+
// Clear the self-reference to prevent inadvertent use and
283+
// inform functions that validate it that the thread is no
284+
// longer available.
285+
t->self = NULL;
282286

283-
// Free all the entire thread block (called map_base because
287+
// Free the entire thread block (called map_base because
284288
// musl normally allocates this using mmap). This region
285289
// includes the pthread structure itself.
286290
unsigned char* block = t->map_base;
287291
dbg("_emscripten_thread_free_data thread=%p map_base=%p", t, block);
292+
#ifndef NDEBUG
288293
// To aid in debugging, set the entire region to zero.
289294
memset(block, 0, sizeof(struct pthread));
295+
#endif
290296
emscripten_builtin_free(block);
291297
}
292298

0 commit comments

Comments
 (0)