Skip to content

Commit ffd817d

Browse files
committed
sem: fix NULL pointer when open CONFIG_PRIORITY_INHERITANCE
set CONFIG_PRIORITY_INHERITANCE=y set CONFIG_SEM_PREALLOCHOLDERS=0 semaphore/sem_holder.c:320:34: runtime error: member access within null pointer of type 'struct tcb_s' #0 0xd8b540 in nxsem_boostholderprio semaphore/sem_holder.c:320 #1 0xd8c1cf in nxsem_boost_priority semaphore/sem_holder.c:703 #2 0xda5dfa in nxsem_wait semaphore/sem_wait.c:145 apache#3 0xda61d9 in nxsem_wait_uninterruptible semaphore/sem_wait.c:248 apache#4 0x12f2477 in media_service_thread0 /home/ligd/platform/dev/apps/examples/hello/hello_main.c:44 apache#5 0x1204154 in pthread_startup pthread/pthread_create.c:59 apache#6 0x1cd906f in pthread_start pthread/pthread_create.c:139 apache#7 0xe72fcb in pre_start sim/sim_initialstate.c:52 Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent 69f3774 commit ffd817d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

sched/semaphore/sem_holder.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static int nxsem_boostholderprio(FAR struct semholder_s *pholder,
319319
* because the thread is already running at a sufficient priority.
320320
*/
321321

322-
if (rtcb->sched_priority > htcb->sched_priority)
322+
if (rtcb && htcb && rtcb->sched_priority > htcb->sched_priority)
323323
{
324324
/* Raise the priority of the holder of the semaphore. This
325325
* cannot cause a context switch because we have preemption
@@ -757,14 +757,13 @@ void nxsem_release_holder(FAR sem_t *sem)
757757
return;
758758
}
759759
}
760-
761-
/* The current task is not a holder */
762-
763-
DEBUGPANIC();
764760
#else
765761
pholder = &sem->holder;
766-
DEBUGASSERT(pholder->htcb == rtcb);
767-
nxsem_freeholder(sem, pholder);
762+
if (pholder->htcb)
763+
{
764+
DEBUGASSERT(pholder->htcb == rtcb);
765+
nxsem_freeholder(sem, pholder);
766+
}
768767
#endif
769768
}
770769
}

0 commit comments

Comments
 (0)