Fixed crash closing database when there are unsaved models

Reported on this thread:
https://groups.google.com/d/msgid/mobile-couchbase/33d8a66d-c4b7-47e2-891f-6c7b345df51d%40googlegroups.com