Free
Free is a function to deallocate memory obtained from malloc and other functions in C. Do not use this tag to refer to free software
Strdup
The strdup() function duplicates a string
Others
Example |
---|
That requires the caller to take the responsibility of free ing the reversed string;strdup is not a great function because it needs to find the length of the string that is being duplicated which means you end up traversing one extra time from question Reverse strings |
In c memory most other things are managed by the programmer so strdup is no worse than forgetting to free malloc ed memory failing to null terminate a string using incorrect format string in scanf and invoking undefined behaviour accessing dangling pointer etc from question Why is strdup considered to be evil |