From 5334c065b444ec52a25c0112be5fb73249eba647 Mon Sep 17 00:00:00 2001 From: cuiziwei Date: Fri, 4 Aug 2023 16:32:45 +0800 Subject: [PATCH] nuttx/tls:Setting the candidtate index to null prevents dangling pointers. Signed-off-by: cuiziwei --- libs/libc/tls/tls_destruct.c | 3 ++- sched/task/task_tls_alloc.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/libc/tls/tls_destruct.c b/libs/libc/tls/tls_destruct.c index 37a6f450ad0..10c56c21aed 100644 --- a/libs/libc/tls/tls_destruct.c +++ b/libs/libc/tls/tls_destruct.c @@ -68,13 +68,14 @@ void tls_destruct(void) if (tlsset & mask) { tls_elem_ptr = (FAR void *)tls->tl_elem[candidate]; - tls->tl_elem[candidate] = 0; destructor = info->ta_tlsdtor[candidate]; if (tls_elem_ptr && destructor) { destructor(tls_elem_ptr); } } + + tls->tl_elem[candidate] = 0; } } diff --git a/sched/task/task_tls_alloc.c b/sched/task/task_tls_alloc.c index 16763544fc4..a26fdecdc03 100644 --- a/sched/task/task_tls_alloc.c +++ b/sched/task/task_tls_alloc.c @@ -114,12 +114,13 @@ void task_tls_destruct(void) if ((g_tlsset & mask) != 0) { elem = info->ta_telem[candidate]; - info->ta_telem[candidate] = 0; dtor = g_tlsdtor[candidate]; if (dtor != NULL && elem != 0) { dtor((void *)elem); } + + info->ta_telem[candidate] = 0; } } }