Add SIGINT handling so valgrind can do its work properly. Also fix 2 memory leaks.