Fix memory leak found by valgrind