| Index: nspr-4.8.6/mozilla/nsprpub/pr/src/md/unix/uxproces.c |
| =================================================================== |
| --- nspr-4.8.6.orig/mozilla/nsprpub/pr/src/md/unix/uxproces.c |
| +++ nspr-4.8.6/mozilla/nsprpub/pr/src/md/unix/uxproces.c |
| @@ -459,6 +459,29 @@ _MD_CreateUnixProcess( |
| #define PID_HASH_MASK ((pid_t) (NBUCKETS - 1)) |
| |
| static pr_PidRecord * |
| +CreatePidRecord(void) |
| +{ |
| + pr_PidRecord *pRec; |
| + pRec = PR_NEWZAP(pr_PidRecord); |
| + pRec->reapedCV = PR_NewCondVar(pr_wp.ml); |
| + if (NULL == pRec->reapedCV) { |
| + PR_DELETE(pRec); |
| + pRec = NULL; |
| + } |
| + return pRec; |
| +} |
| + |
| +static void |
| +DeletePidRecord(pr_PidRecord *pRec) |
| +{ |
| + if (pRec->reapedCV) { |
| + PR_DestroyCondVar(pRec->reapedCV); |
| + pRec->reapedCV = NULL; |
| + } |
| + PR_DELETE(pRec); |
| +} |
| + |
| +static pr_PidRecord * |
| FindPidTable(pid_t pid) |
| { |
| pr_PidRecord *pRec; |
| @@ -533,18 +556,17 @@ ProcessReapedChildInternal(pid_t pid, in |
| |
| pRec = FindPidTable(pid); |
| if (NULL == pRec) { |
| - pRec = PR_NEW(pr_PidRecord); |
| + pRec = CreatePidRecord(); |
| + PR_ASSERT(pRec); |
| pRec->pid = pid; |
| pRec->state = _PR_PID_REAPED; |
| pRec->exitStatus = ExtractExitStatus(status); |
| - pRec->reapedCV = NULL; |
| InsertPidTable(pRec); |
| } else { |
| PR_ASSERT(pRec->state != _PR_PID_REAPED); |
| if (_PR_PID_DETACHED == pRec->state) { |
| - PR_ASSERT(NULL == pRec->reapedCV); |
| DeletePidTable(pRec); |
| - PR_DELETE(pRec); |
| + DeletePidRecord(pRec); |
| } else { |
| PR_ASSERT(_PR_PID_WAITING == pRec->state); |
| PR_ASSERT(NULL != pRec->reapedCV); |
| @@ -793,7 +815,7 @@ PRStatus _MD_DetachUnixProcess(PRProcess |
| PR_Lock(pr_wp.ml); |
| pRec = FindPidTable(process->md.pid); |
| if (NULL == pRec) { |
| - pRec = PR_NEW(pr_PidRecord); |
| + pRec = CreatePidRecord(); |
| if (NULL == pRec) { |
| PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
| retVal = PR_FAILURE; |
| @@ -801,7 +823,6 @@ PRStatus _MD_DetachUnixProcess(PRProcess |
| } |
| pRec->pid = process->md.pid; |
| pRec->state = _PR_PID_DETACHED; |
| - pRec->reapedCV = NULL; |
| InsertPidTable(pRec); |
| } else { |
| PR_ASSERT(_PR_PID_REAPED == pRec->state); |
| @@ -809,9 +830,8 @@ PRStatus _MD_DetachUnixProcess(PRProcess |
| PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); |
| retVal = PR_FAILURE; |
| } else { |
| - DeletePidTable(pRec); |
| - PR_ASSERT(NULL == pRec->reapedCV); |
| - PR_DELETE(pRec); |
| + DeletePidTable(pRec); |
| + DeletePidRecord(pRec); |
| } |
| } |
| PR_DELETE(process); |
| @@ -832,7 +852,7 @@ PRStatus _MD_WaitUnixProcess( |
| PR_Lock(pr_wp.ml); |
| pRec = FindPidTable(process->md.pid); |
| if (NULL == pRec) { |
| - pRec = PR_NEW(pr_PidRecord); |
| + pRec = CreatePidRecord(); |
| if (NULL == pRec) { |
| PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
| retVal = PR_FAILURE; |
| @@ -840,12 +860,6 @@ PRStatus _MD_WaitUnixProcess( |
| } |
| pRec->pid = process->md.pid; |
| pRec->state = _PR_PID_WAITING; |
| - pRec->reapedCV = PR_NewCondVar(pr_wp.ml); |
| - if (NULL == pRec->reapedCV) { |
| - PR_DELETE(pRec); |
| - retVal = PR_FAILURE; |
| - goto done; |
| - } |
| InsertPidTable(pRec); |
| while (!interrupted && _PR_PID_REAPED != pRec->state) { |
| if (PR_WaitCondVar(pRec->reapedCV, |
| @@ -863,16 +877,14 @@ PRStatus _MD_WaitUnixProcess( |
| retVal = PR_FAILURE; |
| } |
| DeletePidTable(pRec); |
| - PR_DestroyCondVar(pRec->reapedCV); |
| - PR_DELETE(pRec); |
| + DeletePidRecord(pRec); |
| } else { |
| PR_ASSERT(_PR_PID_REAPED == pRec->state); |
| - PR_ASSERT(NULL == pRec->reapedCV); |
| DeletePidTable(pRec); |
| if (exitCode) { |
| *exitCode = pRec->exitStatus; |
| } |
| - PR_DELETE(pRec); |
| + DeletePidRecord(pRec); |
| } |
| PR_DELETE(process); |
| |