From c5e6d0c770a2d6cd7a341060ebafbe14c1296608 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Thu, 17 Sep 2015 14:04:01 -0700 Subject: [PATCH] Handle safely winfork failures --- src/compat/process.c | 12 +++++++++++- src/core/worker.c | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/compat/process.c b/src/compat/process.c index 41990fa..c2d7f47 100644 --- a/src/compat/process.c +++ b/src/compat/process.c @@ -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); diff --git a/src/core/worker.c b/src/core/worker.c index 93ff121..85a945a 100644 --- a/src/core/worker.c +++ b/src/core/worker.c @@ -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;