mirror of
https://github.com/apache/nuttx.git
synced 2025-01-12 22:08:35 +08:00
nxsem_destroyholder: Use critical section when destroying holder(s)
Some checks failed
Build Documentation / build-html (push) Has been cancelled
Some checks failed
Build Documentation / build-html (push) Has been cancelled
Otherwise the free holder list will leak, causing either a crash due to holder->htcb = NULL, or the free holder list becomes (erroneously) empty even though most of the holder entries are free.
This commit is contained in:
parent
ad8902a33e
commit
e19e1a8532
1 changed files with 4 additions and 0 deletions
|
@ -558,6 +558,8 @@ void nxsem_initialize_holders(void)
|
||||||
|
|
||||||
void nxsem_destroyholder(FAR sem_t *sem)
|
void nxsem_destroyholder(FAR sem_t *sem)
|
||||||
{
|
{
|
||||||
|
irqstate_t flags = enter_critical_section();
|
||||||
|
|
||||||
/* It might be an error if a semaphore is destroyed while there are any
|
/* It might be an error if a semaphore is destroyed while there are any
|
||||||
* holders of the semaphore (except perhaps the thread that release the
|
* holders of the semaphore (except perhaps the thread that release the
|
||||||
* semaphore itself). We actually have to assume that the caller knows
|
* semaphore itself). We actually have to assume that the caller knows
|
||||||
|
@ -592,6 +594,8 @@ void nxsem_destroyholder(FAR sem_t *sem)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nxsem_foreachholder(sem, nxsem_recoverholders, NULL);
|
nxsem_foreachholder(sem, nxsem_recoverholders, NULL);
|
||||||
|
|
||||||
|
leave_critical_section(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
Loading…
Reference in a new issue