fix serious bug where a segment that was just freed gets selected for
writing. It is hard to reproduce.