From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id 38E30385781D; Tue, 26 Apr 2022 13:33:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38E30385781D 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 r11-9937] 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-11 X-Git-Oldrev: eb6f6f638a547f0330cc7940c5389039b59e4e76 X-Git-Newrev: c5d458ec228b46cf99fe384e0532c309bdfeb6bb Message-Id: <20220426133351.38E30385781D@sourceware.org> Date: Tue, 26 Apr 2022 13:33:51 +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:33:51 -0000 https://gcc.gnu.org/g:c5d458ec228b46cf99fe384e0532c309bdfeb6bb commit r11-9937-gc5d458ec228b46cf99fe384e0532c309bdfeb6bb 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 462230508ab..ebeeb8deda3 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; } /*