Skip to content

Commit

Permalink
nxsem_destroyholder: Use critical section when destroying holder(s)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pussuw committed Dec 27, 2024
1 parent c769b33 commit cbb67a5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sched/semaphore/sem_holder.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ void nxsem_initialize_holders(void)

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
* holders of the semaphore (except perhaps the thread that release the
* semaphore itself). We actually have to assume that the caller knows
Expand Down Expand Up @@ -592,6 +594,8 @@ void nxsem_destroyholder(FAR sem_t *sem)
#endif

nxsem_foreachholder(sem, nxsem_recoverholders, NULL);

leave_critical_section(flags);
}

/****************************************************************************
Expand Down

0 comments on commit cbb67a5

Please sign in to comment.