fix memory errors detected by valgrind