A few more memory leaks.
Add CTRL-C handler to main.cpp for clean exit.