Fixed errors according to Valgrind.