more defensive programming

This commit is contained in:
rsc 2006-09-07 01:56:22 +00:00
parent f70172129c
commit 1133b215d8

5
proc.c
View file

@ -371,7 +371,9 @@ proc_wait(void)
havekids = 0; havekids = 0;
for(i = 0; i < NPROC; i++){ for(i = 0; i < NPROC; i++){
p = &proc[i]; p = &proc[i];
if(p->state != UNUSED && p->ppid == cp->pid){ if(p->state == UNUSED)
continue;
if(p->ppid == cp->pid){
if(p->state == ZOMBIE){ if(p->state == ZOMBIE){
// Found one. // Found one.
kfree(p->mem, p->sz); kfree(p->mem, p->sz);
@ -379,6 +381,7 @@ proc_wait(void)
pid = p->pid; pid = p->pid;
p->state = UNUSED; p->state = UNUSED;
p->pid = 0; p->pid = 0;
p->ppid = 0;
release(&proc_table_lock); release(&proc_table_lock);
return pid; return pid;
} }