aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2020-11-18 17:38:43 +0100
committerVasil Dimov <vd@FreeBSD.org>2021-03-01 12:57:00 +0100
commit545bc5f81d60fa6ff7c5cc43a2e9eef82f911466 (patch)
treea33547b406d578c4b4505dad2087e575d3fbab1f
parent8b6e4b3b23027da263d257b342f5d9a53e4032d5 (diff)
util: fix WriteBinaryFile() claiming success even if error occurred
`fclose()` is flushing any buffered data to disk, so if it fails then that could mean that the data was not completely written to disk. Thus, check if `fclose()` succeeds and only then claim success from `WriteBinaryFile()`.
-rw-r--r--src/util/readwritefile.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/util/readwritefile.cpp b/src/util/readwritefile.cpp
index 15e9d7a9b9..a45c41d367 100644
--- a/src/util/readwritefile.cpp
+++ b/src/util/readwritefile.cpp
@@ -40,6 +40,8 @@ bool WriteBinaryFile(const fs::path &filename, const std::string &data)
fclose(f);
return false;
}
- fclose(f);
+ if (fclose(f) != 0) {
+ return false;
+ }
return true;
}