From 88fe778d9d377b5819c51839bdd842912162230d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 10 Mar 2024 17:54:26 +0000 Subject: [PATCH] BufferedFile: fclose at destruction This is currently indirectly implied by src/bench/load_external.cpp:LoadExternalBlockFile "The file will be closed by LoadExternalBlockFile()." --- src/streams.h | 4 ++++ src/test/fuzz/buffered_file.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/streams.h b/src/streams.h index bc04a2babd..35e9d0c6fb 100644 --- a/src/streams.h +++ b/src/streams.h @@ -520,6 +520,10 @@ public: throw std::ios_base::failure("Rewind limit must be less than buffer size"); } + ~BufferedFile() { fclose(); } + + int fclose() { return m_src.fclose(); } + //! check whether we're at the end of the source file bool eof() const { return m_read_pos == nSrcPos && m_src.feof(); diff --git a/src/test/fuzz/buffered_file.cpp b/src/test/fuzz/buffered_file.cpp index e30c19b265..c4edceddaa 100644 --- a/src/test/fuzz/buffered_file.cpp +++ b/src/test/fuzz/buffered_file.cpp @@ -65,4 +65,8 @@ FUZZ_TARGET(buffered_file) } opt_buffered_file->GetPos(); } + if (opt_buffered_file) { + opt_buffered_file->fclose(); + opt_buffered_file.reset(); + } }