Fix sporadic crashes under Windows