diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 530fa016eb7..0c54b1a2ae2 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -7,6 +7,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -251,16 +252,16 @@ int main(int argc, char **argv) DBConnector config_db(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); DBConnector state_db(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); - OrchDaemon *orchDaemon = new OrchDaemon(&appl_db, &config_db, &state_db); - if (!orchDaemon->init()) - { - SWSS_LOG_ERROR("Failed to initialize orchstration daemon"); - delete orchDaemon; - exit(EXIT_FAILURE); - } + auto orchDaemon = make_shared(&appl_db, &config_db, &state_db); try { + if (!orchDaemon->init()) + { + SWSS_LOG_ERROR("Failed to initialize orchstration daemon"); + exit(EXIT_FAILURE); + } + SWSS_LOG_NOTICE("Notify syncd APPLY_VIEW"); attr.id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD; @@ -270,7 +271,6 @@ int main(int argc, char **argv) if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to notify syncd APPLY_VIEW %d", status); - delete orchDaemon; exit(EXIT_FAILURE); } @@ -285,6 +285,5 @@ int main(int argc, char **argv) SWSS_LOG_ERROR("Failed due to exception: %s", e.what()); } - delete orchDaemon; return 0; } diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index 48b8e5b4271..937c226b4fe 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -471,9 +471,15 @@ void Orch::addConsumer(DBConnector *db, string tableName, int pri) void Orch::addExecutor(string executorName, Executor* executor) { - m_consumerMap.emplace(std::piecewise_construct, + auto inserted = m_consumerMap.emplace(std::piecewise_construct, std::forward_as_tuple(executorName), std::forward_as_tuple(executor)); + + // If there is duplication of executorName in m_consumerMap, logic error + if (!inserted.second) + { + SWSS_LOG_THROW("Duplicated executorName in m_consumerMap: %s", executorName.c_str()); + } } Executor *Orch::getExecutor(string executorName)