fix memory leaks from valgrind output