Fix a bug in ring buffers