From b68d661678c2d4fdc7ef168974ea3f205187c44a Mon Sep 17 00:00:00 2001 From: SuppenGeist Date: Sun, 22 May 2016 13:24:09 +0200 Subject: [PATCH] Close streams properly on shutdown --- src/ak_logger.cpp | 22 ++++++++++++++++++++++ src/ak_logger.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/ak_logger.cpp b/src/ak_logger.cpp index 60e6604..1ccfb95 100644 --- a/src/ak_logger.cpp +++ b/src/ak_logger.cpp @@ -75,4 +75,26 @@ void AKLogger::log(String line) { void AKLogger::shutdown() { if(!isActive) return; + + isActive = false; + + closeAndDeleteOutputStreams(); + closeAndDeleteInputStreams(); +} + +void AKLogger::closeAndDeleteOutputStreams() { + for(SimpleList::iterator it = ostreams.begin(); it != ostreams.end(); it++) { + (*it)->flush(); + (*it)->close(); + delete &(*it); + it = ostreams.erase(it); + } +} + +void AKLogger::closeAndDeleteInputStreams() { + for(SimpleList::iterator it = istreams.begin(); it != istreams.end(); it++) { + (*it)->close(); + delete &(*it); + it = istreams.erase(it); + } } diff --git a/src/ak_logger.h b/src/ak_logger.h index 80ca847..28f46c4 100644 --- a/src/ak_logger.h +++ b/src/ak_logger.h @@ -29,4 +29,6 @@ class AKLogger { String readInputStreams(); void logLineFormat(); + void closeAndDeleteOutputStreams(); + void closeAndDeleteInputStreams(); };