Fix exception thrown when closing a file that was deleted