From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id 26D0B3858C83; Tue, 26 Apr 2022 13:37:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26D0B3858C83 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 r9-10028] 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-9 X-Git-Oldrev: ec84dc14ace2f40e7e06fe321fe557421c6392a6 X-Git-Newrev: 90d877c7834c88426d8c0fd00a3076a5216da319 Message-Id: <20220426133733.26D0B3858C83@sourceware.org> Date: Tue, 26 Apr 2022 13:37:33 +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:37:33 -0000 https://gcc.gnu.org/g:90d877c7834c88426d8c0fd00a3076a5216da319 commit r9-10028-g90d877c7834c88426d8c0fd00a3076a5216da319 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 72376ecda0f..fbc837672a0 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; } /*