summaryrefslogtreecommitdiffstats
path: root/libphobos
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-04-26 14:10:09 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2022-04-26 14:32:11 +0100
commit796b7cbac3d553a91d37c3961b9391fb7e19d0c6 (patch)
tree9efbe189e65e04d19b77e06ab1605eeecbb6c6e3 /libphobos
parentlibstdc++: Add std::atomic<shared_ptr>(nullptr_t) constructor (LWG 3661) (diff)
downloadgcc-796b7cbac3d553a91d37c3961b9391fb7e19d0c6.tar.gz
gcc-796b7cbac3d553a91d37c3961b9391fb7e19d0c6.tar.bz2
gcc-796b7cbac3d553a91d37c3961b9391fb7e19d0c6.tar.xz
libphobos: Don't call free on the TLS array in the emutls destroy function.
Fixes a segfault seen on Darwin when a GC scan is ran after a thread has been destroyed. As the global emutlsArrays hash still has a reference to the array itself, and tries to iterate all elements. Setting the length to zero frees all allocated elements in the array, and ensures that it is skipped when the _d_emutls_scan is called. libphobos/ChangeLog: * libdruntime/gcc/emutls.d (emutlsDestroyThread): Clear the per-thread TLS array, don't call free().
Diffstat (limited to 'libphobos')
-rw-r--r--libphobos/libdruntime/gcc/emutls.d8
1 files changed, 4 insertions, 4 deletions
diff --git a/libphobos/libdruntime/gcc/emutls.d b/libphobos/libdruntime/gcc/emutls.d
index 6d9fb309a30..ee3603206b6 100644
--- a/libphobos/libdruntime/gcc/emutls.d
+++ b/libphobos/libdruntime/gcc/emutls.d
@@ -223,9 +223,9 @@ void** emutlsAlloc(shared __emutls_object* obj) nothrow @nogc
223} 223}
224 224
225/* 225/*
226 * When a thread has finished, remove the TLS array from the GC 226 * When a thread has finished, free all allocated TLS variables and empty the
227 * scan list emutlsArrays, free all allocated TLS variables and 227 * array. The pointer is not free'd as it is stil referenced by the GC scan
228 * finally free the array. 228 * list emutlsArrays, which gets destroyed when druntime is unloaded.
229 */ 229 */
230extern (C) void emutlsDestroyThread(void* ptr) nothrow @nogc 230extern (C) void emutlsDestroyThread(void* ptr) nothrow @nogc
231{ 231{
@@ -237,7 +237,7 @@ extern (C) void emutlsDestroyThread(void* ptr) nothrow @nogc
237 free(entry[-1]); 237 free(entry[-1]);
238 } 238 }
239 239
240 free(arr); 240 arr.length = 0;
241} 241}
242 242
243/* 243/*