Skip to content

Commit

Permalink
[orchagent]: Fix crash during orchagent process exit (sonic-net#974)
Browse files Browse the repository at this point in the history
Avoid crash due to accessing deleted pointer, during process exit.
In this case, FdbOrch was calling detach on PortsOrch which is already deleted
and the memory got returned to Kernel, which resulted in kernel exception.
  • Loading branch information
renukamanavalan authored and stcheng committed Jul 15, 2019
1 parent 758f9e1 commit b926d87
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ OrchDaemon::OrchDaemon(DBConnector *applDb, DBConnector *configDb, DBConnector *
OrchDaemon::~OrchDaemon()
{
SWSS_LOG_ENTER();
for (Orch *o : m_orchList)
delete(o);

/*
* Some orchagents call other agents in their destructor.
* To avoid accessing deleted agent, do deletion in reverse order.
* NOTE: This is stil not a robust solution, as order in this list
* does not strictly match the order of construction of agents.
* For a robust solution, first some cleaning/house-keeping in
* orchagents management is in order.
* For now it fixes, possible crash during process exit.
*/
auto it = m_orchList.rbegin();
for(; it != m_orchList.rend(); ++it) {
delete(*it);
}
}

bool OrchDaemon::init()
Expand Down

0 comments on commit b926d87

Please sign in to comment.