The malloc function performs dynamic memory allocation in C and is part of the standard library
The strdup() function duplicates a string
"You can use either to create a new memory block which is separate from the original but naturally strdup is simpler since it doesn t require a separate malloc strlen call"
from question "Deep copying structs with char arrays in C (How to copy the arrays?)"
"You should know that strdup allocates more memory and returns its pointer which you then overwrite the original pointer returned by malloc so it will be impossible to free that memory since you no longer have the pointers"
from question "Segmentation Fault Using strcat()"
"Or indeed if your system has strdup or you re willing to write an implementation then strdup is much cleaner than malloc + strcpy"
from question "Valgrind - snprintf : Conditional jump or move depends on uninitialised value(s)"