Release locks when `Cursor.insert` fails.

Additionally, attempt to close the open file handle when write fails. If
writes are failing, then the application is in a bad state. We could be
even more particular and report a failed write and close, but first come
first "thrown" is enough to tell the caller that their filesystem is
full or corrupt.

Closes #284.