Skip to content

Commit 8ad31f9

Browse files
committed
Merge #9798: Fix Issue #9775 (Check returned value of fopen)
40f11f8 Fix for issue #9775. Added check for open() returning a NULL pointer. (kirit93)
2 parents 7d46b3e + 40f11f8 commit 8ad31f9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/util.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,13 @@ void OpenDebugLog()
214214
assert(vMsgsBeforeOpenLog);
215215
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
216216
fileout = fopen(pathDebug.string().c_str(), "a");
217-
if (fileout) setbuf(fileout, NULL); // unbuffered
218-
219-
// dump buffered messages from before we opened the log
220-
while (!vMsgsBeforeOpenLog->empty()) {
221-
FileWriteStr(vMsgsBeforeOpenLog->front(), fileout);
222-
vMsgsBeforeOpenLog->pop_front();
217+
if (fileout) {
218+
setbuf(fileout, NULL); // unbuffered
219+
// dump buffered messages from before we opened the log
220+
while (!vMsgsBeforeOpenLog->empty()) {
221+
FileWriteStr(vMsgsBeforeOpenLog->front(), fileout);
222+
vMsgsBeforeOpenLog->pop_front();
223+
}
223224
}
224225

225226
delete vMsgsBeforeOpenLog;
@@ -838,4 +839,4 @@ std::string CopyrightHolders(const std::string& strPrefix)
838839
strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
839840
}
840841
return strCopyrightHolders;
841-
}
842+
}

0 commit comments

Comments
 (0)