Reduce complexity by using strdup().

This patch simplifies a lot of code by using strdup() when appropriate. stdup() is POSIX and also exists on Windows so there shouldn't be any portability concerns.