Fixed shutdown problems with open database: the file was closed before the flush of mmap state