fix pointer invalidated by realloc