Fix intermittent crash in RecordWriteStub, and associated Patch routines