Fix use-after-free issue in the logging library

v1
BuildTools 2023-02-22 01:34:41 -05:00
parent b95359a311
commit d72441f170
1 changed files with 6 additions and 4 deletions

View File

@ -98,11 +98,13 @@ namespace blt::logging {
// by default everything is enabled // by default everything is enabled
LOG_PROPERTIES BLT_LOGGING_PROPERTIES {}; LOG_PROPERTIES BLT_LOGGING_PROPERTIES {};
LogFileWriter writer{"./"}; LogFileWriter* writer = new LogFileWriter{"./"};
void init(LOG_PROPERTIES properties) { void init(LOG_PROPERTIES properties) {
if (properties.m_logToFile && BLT_LOGGING_PROPERTIES.m_directory != properties.m_directory) if (properties.m_logToFile && BLT_LOGGING_PROPERTIES.m_directory != properties.m_directory) {
writer = LogFileWriter{properties.m_directory}; delete(writer);
writer = new LogFileWriter{properties.m_directory};
}
if (properties.m_logToFile) if (properties.m_logToFile)
std::filesystem::create_directory(properties.m_directory); std::filesystem::create_directory(properties.m_directory);
BLT_LOGGING_PROPERTIES = properties; BLT_LOGGING_PROPERTIES = properties;
@ -154,7 +156,7 @@ namespace blt::logging {
} }
if (BLT_LOGGING_PROPERTIES.m_logToFile) { if (BLT_LOGGING_PROPERTIES.m_logToFile) {
writer.writeLine(fileString); writer->writeLine(fileString);
} }
} }