From a5b870a0b394a8c30bcf49dd3d36c3a8a60f8c59 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Tue, 20 Feb 2024 01:26:00 -0600 Subject: [PATCH] io: Always discard file_ pointer on close() --- src/io/streams.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/io/streams.cpp b/src/io/streams.cpp index bfcadb84f..17d03e0ad 100644 --- a/src/io/streams.cpp +++ b/src/io/streams.cpp @@ -157,14 +157,12 @@ void FileStream::close() if (std::fclose((std::FILE*)(this->file_)) != 0) { + // The FILE is now invalid even though fclose failed. + // There is nothing we can do but abandon the pointer. + file_ = nullptr; int err = errno; throw make_exception_from_errno(err); } - if (std::ferror((std::FILE*)(this->file_)) != 0) - { - int err = errno; - throw make_exception_from_errno(err); - } file_ = nullptr; }