fix memory leak found by valgrind