From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id A185D3858C53; Tue, 26 Apr 2022 13:32:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A185D3858C53 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8268] libphobos: Don't call free on the TLS array in the emutls destroy function. X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/master X-Git-Oldrev: 41ccd683f0002d7b5127aafc00dcd59e7837f0ab X-Git-Newrev: 796b7cbac3d553a91d37c3961b9391fb7e19d0c6 Message-Id: <20220426133250.A185D3858C53@sourceware.org> Date: Tue, 26 Apr 2022 13:32:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Apr 2022 13:32:50 -0000 https://gcc.gnu.org/g:796b7cbac3d553a91d37c3961b9391fb7e19d0c6 commit r12-8268-g796b7cbac3d553a91d37c3961b9391fb7e19d0c6 Author: Iain Buclaw Date: Tue Apr 26 14:10:09 2022 +0100 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(). Diff: --- libphobos/libdruntime/gcc/emutls.d | 8 ++++---- 1 file 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 } /* - * When a thread has finished, remove the TLS array from the GC - * scan list emutlsArrays, free all allocated TLS variables and - * finally free the array. + * When a thread has finished, free all allocated TLS variables and empty the + * array. The pointer is not free'd as it is stil referenced by the GC scan + * list emutlsArrays, which gets destroyed when druntime is unloaded. */ extern (C) void emutlsDestroyThread(void* ptr) nothrow @nogc { @@ -237,7 +237,7 @@ extern (C) void emutlsDestroyThread(void* ptr) nothrow @nogc free(entry[-1]); } - free(arr); + arr.length = 0; } /*