strdup(3) allocates memory for a copy of the string, does the copy and returns a pointer to it. If there is no sufficient memory NULL is returned and the global errno is set to ENOMEM. We do a sanity check to see if it was possible to allocat enough memory.
Also as we allocate memory, we need to free this memory used. OR it will going out of scope leaks the storage it points to.