strdup before running buf through strtok

in function array_of_segments, no need to edit this string in place