Fix not to attempt to close a file handle that is not open.