fixed memory leaks in tests, thanks to valgrind