- wxEndProcessData *proc_data = (wxEndProcessData*)data;
- wxLogDebug(wxT("Process ended"));
- int status = 0;
- int rc = waitpid(abs(proc_data->pid), &status, WNOHANG);
- if(!rc)
- {
- wxLogDebug(wxT("Mach port was invalidated, but process hasn't terminated!"));
- return;
- }
- if((rc != -1) && WIFEXITED(status))
- proc_data->exitcode = WEXITSTATUS(status);
- else
- proc_data->exitcode = -1;
- wxHandleProcessTermination(proc_data);
+ /*
+ Either our pipe was closed or the process ended successfully. Either way,
+ we're done. It's not if waitpid is going to magically succeed when
+ we get fired again. CFSocketInvalidate closes the fd for us and also
+ invalidates the run loop source for us which should cause it to
+ release the CFSocket (thus causing it to be deallocated) and remove
+ itself from the runloop which should release it and cause it to also
+ be deallocated. Of course, it's possible the RunLoop hangs onto
+ one or both of them by retaining/releasing them within its stack
+ frame. However, that shouldn't be depended on. Assume that s is
+ deallocated due to the following call.
+ */
+ CFSocketInvalidate(s);
+
+ // Now tell wx that the process has ended.
+ wxHandleProcessTermination(static_cast<wxEndProcessData *>(info));