diff --git a/ChangeLog b/ChangeLog index 0b7fd32e96..46ef797567 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Mar 23 00:12:16 2011 Tajima Akio + + * win32/win32.c: wait process real termination after reading + exit code. fixes #4518 + Tue Mar 22 21:20:10 2011 NARUSE, Yui * lib/rubygems/test_case.rb: save current dir to @current_dir diff --git a/win32/win32.c b/win32/win32.c index 1805fe1015..6c9da16c14 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -3549,6 +3549,7 @@ poll_child_status(struct ChildRecord *child, int *stat_loc) if (!GetExitCodeProcess(child->hProcess, &exitcode)) { /* If an error occured, return immediatly. */ + error_exit: err = GetLastError(); if (err == ERROR_INVALID_PARAMETER) errno = ECHILD; @@ -3562,7 +3563,12 @@ poll_child_status(struct ChildRecord *child, int *stat_loc) return -1; } if (exitcode != STILL_ACTIVE) { - /* If already died, return immediatly. */ + rb_pid_t pid; + /* If already died, wait process's real termination. */ + if (rb_w32_wait_events_blocking(&child->hProcess, 1, INFINITE) != WAIT_OBJECT_0) { + goto error_exit; + } + pid = child->pid; rb_pid_t pid = child->pid; CloseChildHandle(child); if (stat_loc) *stat_loc = exitcode << 8;