Make forking code paths more robust.

Use fflush(NULL) before fork().
Avoid allocations after fork().
Use _exit() instead of exit().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>