Fixed invalid memory access valgrind failure.