diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index a627d8c2e42..47de010bad8 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -166,9 +166,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; @@ -208,7 +210,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 20d40a9045e..06798c73002 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -80,7 +80,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 */ @@ -229,7 +233,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. */ @@ -272,8 +276,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;