Fix problem detected by valgrind