Seebs <usenet-> writes:
[...]
> The most interesting question, I think, is:
>
> Can there ever be a valid input to free(), such that the implementation
> cannot actually free the memory? I can easily describe an implementation
> in which this could be the case. You could construct an implementation in
> which there was some sort of "free list" which could require allocation
> in order to add items to that list, and if you had precisely filled available
> memory, it could be that you couldn't free something because there'd be no
> way to add it to the available-things list.
>
> That would be an unusual implementation, at best, but I'm not sure that it
> is prohibited.
>
> Of course, there'd be no way to find OUT that this had happened.
Well, it would violate the requirement that "The free function causes
the space pointed to by ptr to be deallocated, that is, made available
for further allocation." (C99 7.20.3.2p2), so one could argue that
it would be as non-conforming as this implementation:
void free(void *ptr)
{
/* nyaah nyaah! */
}
But yes, as long as there are no visible symptoms of the failure,
it can't be detected. (Failure of later allocations doesn't count,
since that can happen for any arbitrary reasons.)
Practically speaking, of course, the implementation could use the
space being freed to hold any bookkeeping data for the free list,
but implementations aren't required to behave sanely.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"