This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 0cf5fd52ce0 sched/semaphore: Check the semaphore before using it in 
nxsem_destroy().
0cf5fd52ce0 is described below

commit 0cf5fd52ce0cfab07969831c48b960a7a549d4a6
Author: hujun5 <[email protected]>
AuthorDate: Tue Nov 24 19:20:30 2026 +0800

    sched/semaphore: Check the semaphore before using it in nxsem_destroy().
    
    nxsem_destroy() read the flags of the semaphore to set up its locals
    before DEBUGASSERT(sem != NULL), so a NULL semaphore faulted before the
    assertion could report it.  Set the locals up after the check.
    
    Signed-off-by: hujun5 <[email protected]>
    Signed-off-by: ganjing <[email protected]>
---
 sched/semaphore/sem_destroy.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sched/semaphore/sem_destroy.c b/sched/semaphore/sem_destroy.c
index 4bafe8ccdb5..8848a4a1080 100644
--- a/sched/semaphore/sem_destroy.c
+++ b/sched/semaphore/sem_destroy.c
@@ -60,12 +60,16 @@
 int nxsem_destroy(FAR sem_t *sem)
 {
   int32_t old;
-  bool mutex = NXSEM_IS_MUTEX(sem);
-  FAR atomic_t *val = mutex ? NXSEM_MHOLDER(sem) : NXSEM_COUNT(sem);
-  int32_t new = mutex ? NXSEM_NO_MHOLDER : 1;
+  bool mutex;
+  FAR atomic_t *val;
+  int32_t new;
 
   DEBUGASSERT(sem != NULL);
 
+  mutex = NXSEM_IS_MUTEX(sem);
+  val = mutex ? NXSEM_MHOLDER(sem) : NXSEM_COUNT(sem);
+  new = mutex ? NXSEM_NO_MHOLDER : 1;
+
   /* There is really no particular action that we need
    * take to destroy a semaphore.  We will just reset
    * the count to some reasonable value (0) and release

Reply via email to