The job of realloc in this place is to shrink (not to grow) the allocated buffer so it just occupies the space it needs, not more.