Today I was trying to call strerror
POSIX function. It returns a char*
, and now I am not sure whether to free
it or not to free
it.
The application shall not modify the string returned.
I think the returning pointer is supposed to be a pointer to a internal static buffer, and in that case, I should never touch it. But, it just says "do not modify", and doesn't talk about memory ownership at all. I am confusing. I would assume "no touch" as "system owns, caller borrows", but still I am not confident because it's just my inference rather than a promise or definition.
I am not very familiar with C/POSIX programming. I think there must be a well established convention or explicit rules for this, but I couldn't find any.
What is memory ownership rule of C/POSIX functions?