From 053d27c3d5b5e6e1c20b4f1ad125d4130611c2d7 Mon Sep 17 00:00:00 2001 From: YeungKC <11473691+YeungKC@users.noreply.github.com> Date: Sun, 18 Oct 2026 15:17:17 +0900 Subject: [PATCH] mixin_logger: free the log file on rotation and lock SetFileLeading WriteLog closed the std::ofstream when the file reached the size limit but did not delete it, so each rotation leaked the stream and its buffer. Delete the stream instead. SetFileLeading changed the header string without the mutex that WriteLog holds while it writes the header to a new file, so a header could be written from a partly changed string. Hold the same mutex in SetFileLeading. --- packages/mixin_logger/src/mixin_logger.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/mixin_logger/src/mixin_logger.cpp b/packages/mixin_logger/src/mixin_logger.cpp index eddac0d8..5afb1dff 100644 --- a/packages/mixin_logger/src/mixin_logger.cpp +++ b/packages/mixin_logger/src/mixin_logger.cpp @@ -158,12 +158,11 @@ namespace mixin_logger { } ~LoggerContext() { - if (file_ != nullptr) { - file_->close(); - } + delete file_; } void SetFileLeading(const std::string &file_leading) { + std::lock_guard lock(mutex_); file_leading_ = file_leading; } @@ -184,7 +183,7 @@ namespace mixin_logger { file_size_ += int64_t(write); if (file_size_ >= max_file_size_) { - file_->close(); + delete file_; file_ = nullptr; file_size_ = 0; }