Replaced mallo/strcpy by strdup where possible.