Fix invalid memory access error found by valgrind