Fix thread safety issues in GetLogPrefix

This commit is contained in:
Jonathan G Rennison
2023-12-29 23:56:33 +00:00
parent 3683fdce6a
commit 74a2cd5123
3 changed files with 17 additions and 10 deletions

View File

@@ -53,7 +53,8 @@ static void IConsoleWriteToLogFile(const char *string)
{
if (_iconsole_output_file != nullptr) {
/* if there is an console output file ... also print it there */
const char *header = GetLogPrefix();
log_prefix prefix_writer;
const char *header = prefix_writer.GetLogPrefix();
if ((strlen(header) != 0 && fwrite(header, strlen(header), 1, _iconsole_output_file) != 1) ||
fwrite(string, strlen(string), 1, _iconsole_output_file) != 1 ||
fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
@@ -115,7 +116,7 @@ void IConsolePrint(TextColour colour_code, const char *string)
if (_network_dedicated) {
NetworkAdminConsole("console", str);
fprintf(stdout, "%s%s\n", GetLogPrefix(), str);
fprintf(stdout, "%s%s\n", log_prefix().GetLogPrefix(), str);
fflush(stdout);
IConsoleWriteToLogFile(str);
free(str); // free duplicated string since it's not used anymore