From http://en.cppreference.com/w/c/memory/malloc :
The returned pointer must be deallocated with free() or realloc().
From http://en.cppreference.com/w/c/memory/calloc :
The returned pointer must be deallocated with free() or realloc().
Strictly speaking, why must the returning pointer be deallocated?
Now I know that POSIX mandates the memory will be freed upon program termination so in practice calling malloc
and terminating immediately will not do any harm. But that's not what I'm asking about.
Is this hard requirement ("MUST be deallocated") present in the C Standard, or is this an invention of cppreference contributors, to urge programmers not to leak memory? If such a hard requirement is present in the Standard, does this mean that, as per the C Standard (POSIX and other OS related things aside!), the program is UB if a pointer returned by malloc
is not free
'd, or does the Standard define consequences of failing to meet this requirement? (This would be particularly interesting, because this would possibly mean that the Standard deals with what happens when the program has already terminated!)