fix memory leak in the lib
Circular buffer for future use