From efbbf1bfb64e3e49fc19c545a46b63fffdc364a3 Mon Sep 17 00:00:00 2001 From: Tom Epperly Date: Thu, 16 Mar 2017 14:57:14 -0700 Subject: [PATCH] Add code to ensure not nullptr references. Ensure pipe is closed in all eventualities. --- src/easylogging++.cc | 12 ++++++++++-- src/easylogging++.h | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/easylogging++.cc b/src/easylogging++.cc index 9ab5a2d3c..ed57a5544 100644 --- a/src/easylogging++.cc +++ b/src/easylogging++.cc @@ -613,7 +613,10 @@ void Logger::flush(Level level, base::type::fstream_t* fs) { } if (fs != nullptr) { fs->flush(); - m_unflushedCount.find(level)->second = 0; + std::map::iterator i = m_unflushedCount.find(level); + if (i != m_unflushedCount.end()) { + i->second = 0; + } } } @@ -996,6 +999,9 @@ const std::string OS::getBashOutput(const char* command) { } return std::string(hBuff); } + else { + pclose(proc); + } return std::string(); #else ELPP_UNUSED(command); @@ -1260,7 +1266,9 @@ bool CommandLineArgs::hasParamWithValue(const char* paramKey) const { } const char* CommandLineArgs::getParamValue(const char* paramKey) const { - return m_paramsWithValue.find(std::string(paramKey))->second.c_str(); + std::map::const_iterator i = + m_paramsWithValue.find(std::string(paramKey)); + return (i != m_paramsWithValue.end()) ? i->second.c_str() : ""; } bool CommandLineArgs::hasParam(const char* paramKey) const { diff --git a/src/easylogging++.h b/src/easylogging++.h index 08239f8a2..3fefaea43 100644 --- a/src/easylogging++.h +++ b/src/easylogging++.h @@ -2296,7 +2296,9 @@ class Logger : public base::threading::ThreadSafe, public Loggable { void flush(Level level, base::type::fstream_t* fs); inline bool isFlushNeeded(Level level) { - return ++m_unflushedCount.find(level)->second >= m_typedConfigurations->logFlushThreshold(level); + std::map::iterator i = m_unflushedCount.find(level); + return (i != m_unflushedCount.end()) && + (++(i->second) >= m_typedConfigurations->logFlushThreshold(level)); } inline LogBuilder* logBuilder(void) const {