diff --git a/sched/sched/sched_gettcb.c b/sched/sched/sched_gettcb.c index 9ee502cce33..3e38f51b3fb 100644 --- a/sched/sched/sched_gettcb.c +++ b/sched/sched/sched_gettcb.c @@ -56,6 +56,8 @@ FAR struct tcb_s *nxsched_get_tcb(pid_t pid) irqstate_t flags; int hash_ndx; + flags = enter_critical_section(); + /* Verify whether g_pidhash hash table has already been allocated and * whether the PID is within range. */ @@ -68,24 +70,22 @@ FAR struct tcb_s *nxsched_get_tcb(pid_t pid) * terminating asynchronously. */ - flags = enter_critical_section(); - /* Get the hash_ndx associated with the pid */ hash_ndx = PIDHASH(pid); /* Verify that the correct TCB was found. */ - if (g_pidhash && pid == g_pidhash[hash_ndx]->pid) + if (g_pidhash[hash_ndx] != NULL && pid == g_pidhash[hash_ndx]->pid) { /* Return the TCB associated with this pid (if any) */ ret = g_pidhash[hash_ndx]; } - - leave_critical_section(flags); } + leave_critical_section(flags); + /* Return the TCB. */ return ret;