From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id 9374D3858C83; Tue, 26 Apr 2022 13:35:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9374D3858C83 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 r10-10581] 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/releases/gcc-10 X-Git-Oldrev: 84c86d3df27c8cabc6397b6ec710b35dfc24c40c X-Git-Newrev: 0bb57657f20b9b2d9b43b8e1d0748bd6367177f2 Message-Id: <20220426133500.9374D3858C83@sourceware.org> Date: Tue, 26 Apr 2022 13:35:00 +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:35:00 -0000 https://gcc.gnu.org/g:0bb57657f20b9b2d9b43b8e1d0748bd6367177f2 commit r10-10581-g0bb57657f20b9b2d9b43b8e1d0748bd6367177f2 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(). (cherry picked from commit 796b7cbac3d553a91d37c3961b9391fb7e19d0c6) 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 7e4a1d6f8de..6be72db4c09 100644 --- a/libphobos/libdruntime/gcc/emutls.d +++ b/libphobos/libdruntime/gcc/emutls.d @@ -222,9 +222,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 { @@ -236,7 +236,7 @@ extern (C) void emutlsDestroyThread(void* ptr) nothrow @nogc free(entry[-1]); } - free(arr); + arr.length = 0; } /*