diff --git a/src/oatpp/core/base/Environment.cpp b/src/oatpp/core/base/Environment.cpp index 852cff5c..a78ebe01 100644 --- a/src/oatpp/core/base/Environment.cpp +++ b/src/oatpp/core/base/Environment.cpp @@ -216,10 +216,12 @@ void Environment::init(const std::shared_ptr& logger) { } void Environment::destroy(){ - if(getComponents().size() > 0) { + { std::lock_guard lock(getComponentsMutex()); - throw std::runtime_error("[oatpp::base::Environment::destroy()]: Error. " - "Invalid state. Leaking components"); + if(getComponents().size() > 0) { + throw std::runtime_error("[oatpp::base::Environment::destroy()]: Error. " + "Invalid state. Leaking components"); + } } m_logger.reset();