Skip to content

Commit 3ccab64

Browse files
committed
Merge #16212: addrdb: Avoid eating inodes - remove temporary files created by SerializeFileDB in case of errors
d975338 addrdb: Remove temporary files created in SerializeFileDB. Fixes non-determinism in unit tests. (practicalswift) Pull request description: Remove temporary files created in `SerializeFileDB` in case of errors. _Edit: Previously this was hit non-deterministically from the tests: that is no longer the case but the cleanup issue remains :-)_ ACKs for top commit: laanwj: code-review ACK d975338 Tree-SHA512: e72b74b8de411f433bd8bb354cacae07ab75a240db6232bc6a37802ccd8086bff5275ce3d196ddde033d8ab9e2794bb8f60eb83554af7ec2e9f91d6186cb4647
2 parents 1212808 + d975338 commit 3ccab64

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/addrdb.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,30 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
4444
fs::path pathTmp = GetDataDir() / tmpfn;
4545
FILE *file = fsbridge::fopen(pathTmp, "wb");
4646
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
47-
if (fileout.IsNull())
47+
if (fileout.IsNull()) {
48+
fileout.fclose();
49+
remove(pathTmp);
4850
return error("%s: Failed to open file %s", __func__, pathTmp.string());
51+
}
4952

5053
// Serialize
51-
if (!SerializeDB(fileout, data)) return false;
52-
if (!FileCommit(fileout.Get()))
54+
if (!SerializeDB(fileout, data)) {
55+
fileout.fclose();
56+
remove(pathTmp);
57+
return false;
58+
}
59+
if (!FileCommit(fileout.Get())) {
60+
fileout.fclose();
61+
remove(pathTmp);
5362
return error("%s: Failed to flush file %s", __func__, pathTmp.string());
63+
}
5464
fileout.fclose();
5565

5666
// replace existing file, if any, with new file
57-
if (!RenameOver(pathTmp, path))
67+
if (!RenameOver(pathTmp, path)) {
68+
remove(pathTmp);
5869
return error("%s: Rename-into-place failed", __func__);
70+
}
5971

6072
return true;
6173
}

0 commit comments

Comments
 (0)