aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2019-06-14 08:30:43 +0200
committerfanquake <fanquake@gmail.com>2019-09-24 07:53:29 +0800
commit1175410be5959f783f0a5276451b775dc340e420 (patch)
tree3f9e9cf10eff8b09da886ee45c419186ccca82e9 /src
parentc52dd120fd6498ee73b7652e3b0e5380124a5502 (diff)
downloadbitcoin-1175410be5959f783f0a5276451b775dc340e420.tar.xz
addrdb: Remove temporary files created in SerializeFileDB. Fixes non-determinism in unit tests.
Github-Pull: #16212 Rebased-From: d9753383b9e1b61d19d98bcd1d66607f398c7e9f
Diffstat (limited to 'src')
-rw-r--r--src/addrdb.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/addrdb.cpp b/src/addrdb.cpp
index c6083f5554..db936486b6 100644
--- a/src/addrdb.cpp
+++ b/src/addrdb.cpp
@@ -44,18 +44,30 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
fs::path pathTmp = GetDataDir() / tmpfn;
FILE *file = fsbridge::fopen(pathTmp, "wb");
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
- if (fileout.IsNull())
+ if (fileout.IsNull()) {
+ fileout.fclose();
+ remove(pathTmp);
return error("%s: Failed to open file %s", __func__, pathTmp.string());
+ }
// Serialize
- if (!SerializeDB(fileout, data)) return false;
- if (!FileCommit(fileout.Get()))
+ if (!SerializeDB(fileout, data)) {
+ fileout.fclose();
+ remove(pathTmp);
+ return false;
+ }
+ if (!FileCommit(fileout.Get())) {
+ fileout.fclose();
+ remove(pathTmp);
return error("%s: Failed to flush file %s", __func__, pathTmp.string());
+ }
fileout.fclose();
// replace existing file, if any, with new file
- if (!RenameOver(pathTmp, path))
+ if (!RenameOver(pathTmp, path)) {
+ remove(pathTmp);
return error("%s: Rename-into-place failed", __func__);
+ }
return true;
}