Add valgrind test and fix memory leak in unit test