[utils] Add a function for cleaning up buffers.