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-08-04 16:32:45 +08:00 committed by Xiang Xiao
parent 8ffde7cf16
commit 5334c065b4
2 changed files with 4 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}
}