Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 May 2026 15:27:06 +0000
From:      ShengYi Hung <aokblast@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 9d200dc7103a - stable/14 - libc: Fix dtor order in __cxa_thread_atexit
Message-ID:  <6a19b04a.308b7.766e2cf8@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by aokblast:

URL: https://cgit.FreeBSD.org/src/commit/?id=9d200dc7103a6ca2112ab0ea47edc28b2141e14e

commit 9d200dc7103a6ca2112ab0ea47edc28b2141e14e
Author:     ShengYi Hung <aokblast@FreeBSD.org>
AuthorDate: 2026-03-12 13:40:34 +0000
Commit:     ShengYi Hung <aokblast@FreeBSD.org>
CommitDate: 2026-05-29 15:25:42 +0000

    libc: Fix dtor order in __cxa_thread_atexit
    
    The thread_local variable may creates another thread_local variable
    inside its dtor. This new object is immediately be registered in
    __cxa_thread_atexit() and need to be freed before processing another
    variable.
    
    This fixes the libcxx test thread_local_destruction_order.pass.cpp.
    
    Reported by:    kib
    Approved by:    lwhsu (mentor)
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D55826
    
    (cherry picked from commit 9d26b82826d9962d5085bc5d9df7f8a762c57602)
---
 lib/libc/stdlib/cxa_thread_atexit_impl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libc/stdlib/cxa_thread_atexit_impl.c b/lib/libc/stdlib/cxa_thread_atexit_impl.c
index 3123bd12dca8..3d742d90fb44 100644
--- a/lib/libc/stdlib/cxa_thread_atexit_impl.c
+++ b/lib/libc/stdlib/cxa_thread_atexit_impl.c
@@ -119,9 +119,9 @@ walk_cb_nocall(struct cxa_thread_dtor *dtor __unused)
 static void
 cxa_thread_walk(void (*cb)(struct cxa_thread_dtor *))
 {
-	struct cxa_thread_dtor *dtor, *tdtor;
+	struct cxa_thread_dtor *dtor;
 
-	LIST_FOREACH_SAFE(dtor, &dtors, entry, tdtor) {
+	while ((dtor = LIST_FIRST(&dtors)) != NULL) {
 		LIST_REMOVE(dtor, entry);
 		cb(dtor);
 		free(dtor);


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a19b04a.308b7.766e2cf8>