diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index 53922239af..543a2a7e4b 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -167,9 +167,11 @@ int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options) */ ctcb = nxsched_get_tcb((pid_t)id); - if (ctcb != NULL) + if (ctcb && ctcb->group) { - if (ctcb->group->tg_ppid != rtcb->group->tg_pid) + /* Make sure that the thread it is our child. */ + + if (ctcb->group->tg_ppid != rtcb->pid) { ret = -ECHILD; goto errout; @@ -209,7 +211,7 @@ int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options) ctcb = nxsched_get_tcb((pid_t)id); - if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->group->tg_pid) + if (!ctcb || !ctcb->group || ctcb->group->tg_ppid != rtcb->pid) { ret = -ECHILD; goto errout; diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 64c5af3728..d13b718964 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -81,7 +81,11 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) /* Then the task group corresponding to this PID */ group = ctcb->group; - DEBUGASSERT(group); + if (group == NULL) + { + ret = -ECHILD; + goto errout; + } /* Lock this group so that it cannot be deleted until the wait completes */ @@ -230,7 +234,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) */ ctcb = nxsched_get_tcb(pid); - if (ctcb != NULL) + if (ctcb && ctcb->group) { /* Make sure that the thread it is our child. */ @@ -273,8 +277,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options) */ ctcb = nxsched_get_tcb(pid); - - if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->group->tg_pid) + if (!ctcb || !ctcb->group || ctcb->group->tg_ppid != rtcb->pid) { ret = -ECHILD; goto errout;