nuttx/tls:Setting the candidtate index to null prevents dangling pointers.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
This commit is contained in:
cuiziwei
2023-07-10 10:08:50 +08:00
committed by Xiang Xiao
parent a6fcb0a5a9
commit 8ffde7cf16
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -60,7 +60,7 @@ void tls_destruct(void)
DEBUGASSERT(info != NULL);
tlsset = info->ta_tlsset;
for (candidate = 0; candidate < CONFIG_TLS_NELEM; candidate++)
for (candidate = CONFIG_TLS_NELEM - 1; candidate >= 0; candidate--)
{
/* Is this candidate index available? */
@@ -68,6 +68,7 @@ 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)
{
+2 -1
View File
@@ -108,12 +108,13 @@ void task_tls_destruct(void)
tls_dtor_t dtor;
FAR struct task_info_s *info = task_get_info();
for (candidate = 0; candidate < CONFIG_TLS_TASK_NELEM; candidate++)
for (candidate = CONFIG_TLS_TASK_NELEM - 1; candidate >= 0; candidate--)
{
tls_task_ndxset_t mask = (tls_task_ndxset_t)1 << candidate;
if ((g_tlsset & mask) != 0)
{
elem = info->ta_telem[candidate];
info->ta_telem[candidate] = 0;
dtor = g_tlsdtor[candidate];
if (dtor != NULL && elem != 0)
{