fix invalid pointer cause by realloc