From d72441f1703fa44d397b960e4e9e761f07786505 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 22 Feb 2023 01:34:41 -0500 Subject: [PATCH] Fix use-after-free issue in the logging library --- src/blt/std/logging.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/blt/std/logging.cpp b/src/blt/std/logging.cpp index 60b2730..d603c2a 100644 --- a/src/blt/std/logging.cpp +++ b/src/blt/std/logging.cpp @@ -98,11 +98,13 @@ namespace blt::logging { // by default everything is enabled LOG_PROPERTIES BLT_LOGGING_PROPERTIES {}; - LogFileWriter writer{"./"}; + LogFileWriter* writer = new LogFileWriter{"./"}; void init(LOG_PROPERTIES properties) { - if (properties.m_logToFile && BLT_LOGGING_PROPERTIES.m_directory != properties.m_directory) - writer = LogFileWriter{properties.m_directory}; + if (properties.m_logToFile && BLT_LOGGING_PROPERTIES.m_directory != properties.m_directory) { + delete(writer); + writer = new LogFileWriter{properties.m_directory}; + } if (properties.m_logToFile) std::filesystem::create_directory(properties.m_directory); BLT_LOGGING_PROPERTIES = properties; @@ -154,7 +156,7 @@ namespace blt::logging { } if (BLT_LOGGING_PROPERTIES.m_logToFile) { - writer.writeLine(fileString); + writer->writeLine(fileString); } }