Fix potential use-after-free in LogPrintStr(...)
.
freopen(…)
frees m_fileout
.
Fix potential use-after-free in LogPrintStr(...)
.
freopen(…)
frees m_fileout
.
`LogPrintStr` returns the number of characters printed. This number is
doubled if both logging to console and logging to file is enabled. As
the return value is never used, I've opted to remove it instead of try
to fix it.
Credit: @laanwj
I don’t think this patch is really correct – in the usual failure case where the old file handle is closed, but a new file can’t be (re)opened (due to permissions, eg), we’ll silently drop the current log message, then start writing any future log messages to the m_msgs_before_open buffer, which will never be cleared. Am I missing something?
If I’m not, seems like better behaviour might be something like:
0 if (m_reopen_file) {
1 m_reopen_file = false;
2 FILE* new_fileout = fopen(m_file_path, "a");
3 if (!new_fileout) {
4 // release m_file_mutex first
5 LogPrintf("Failed to reopen log file %s\n", m_file_path);
6 } else {
7 fflush(m_fileout);
8 fclose(m_fileout);
9 m_fileout = new_fileout;
10 }
11 }
(Would it make sense to do StartShutdown() if logging stops working?)