Fix to close open file object