Handle safely winfork failures

This commit is contained in:
Snaipe 2015-09-17 14:04:01 -07:00
parent 1d908327d8
commit c5e6d0c770
2 changed files with 12 additions and 2 deletions

View file

@ -290,7 +290,17 @@ s_proc_handle *fork_process() {
ResumeThread(info.hThread);
CloseHandle(info.hThread);
while (!ctx->resumed); // wait until the child has initialized itself
// wait until the child has initialized itself
while (!ctx->resumed) {
DWORD exit;
GetExitCodeProcess(info.hProcess, &exit);
if (exit != STILL_ACTIVE) {
UnmapViewOfFile(ctx);
CloseHandle(sharedMem);
CloseHandle(info.hProcess);
return (void *) -1;
}
}
UnmapViewOfFile(ctx);
CloseHandle(sharedMem);

View file

@ -91,7 +91,7 @@ struct process *spawn_test_worker(struct criterion_test *test,
s_proc_handle *proc = fork_process();
if (proc == (void *) -1) {
return NULL;
abort();
} else if (proc == NULL) {
run_worker(&g_worker_context);
return NULL;