Notice this comment in the code:
space for char[N] and data to keep track of what is allocated and what is not (e.g., a top-of-stack pointer)
In my opinion, only a top-of-stack pointer isn’t enough for this interface. Instead, we need to maintain a list of pointers where we allocated so we can correctly revert the last allocation when we free()
.
Am I wrong or is there some mistake in the book?