fix valgrind reported invalid access error