Fix leaks from valgrind analysis. Stop server cleanly