Frees memory and terminates on SIGINT.