mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 13:52:22 +08:00
nuttx/tls:Setting the candidtate index to null prevents dangling pointers.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user