mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
Explicitly close all AutoFiles that have been written
There is no way to report a close error from `AutoFile` destructor. Such an error could be serious if the file has been written to because it may mean the file is now corrupted (same as if write fails). So, change all users of `AutoFile` that use it to write data to explicitly close the file and handle a possible error.
This commit is contained in:
@@ -4005,6 +4005,11 @@ static void CaptureMessageToFile(const CAddress& addr,
|
||||
uint32_t size = data.size();
|
||||
ser_writedata32(f, size);
|
||||
f << data;
|
||||
|
||||
if (f.fclose() != 0) {
|
||||
throw std::ios_base::failure(
|
||||
strprintf("Error closing %s after write, file contents are likely incomplete", fs::PathToString(path)));
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void(const CAddress& addr,
|
||||
|
||||
Reference in New Issue
Block a user