fix a race in buffer.c