Are you sure that the buffer is either cleared or cleared and filled through every exit path?