Tra l'altro, strdup in quel codice non serve a niente, anzi, dà un memory leak...
Amaro C++, il gusto pieno dell'undefined behavior.
Regole del Forum