ensure to check NULL in malloc/realloc/strdup.