Fixed mem leaks at --check-and-run
Fixed segfaults when running tests. Using global shared_ptr and fork is not a good idea.