Skip to content

Commit

Permalink
Crash when ExchangeContext is leaked
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost authored and bzbarsky-apple committed Apr 21, 2021
1 parent 7883312 commit a0639a7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 37 deletions.
31 changes: 0 additions & 31 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,37 +304,6 @@ void ExchangeContext::Free()
SYSTEM_STATS_DECREMENT(chip::System::Stats::kExchangeMgr_NumContexts);
}

void ExchangeContext::ForceFree()
{
VerifyOrDie(mExchangeMgr != nullptr);

ExchangeManager * em = mExchangeMgr;

if (mDelegate != nullptr)
{
mDelegate->OnExchangeClosing(this);
}
mDelegate = nullptr;

CancelResponseTimer();

mExchangeMgr = nullptr;

em->DecrementContextsInUse();

if (mExchangeACL != nullptr)
{
chip::Platform::Delete(mExchangeACL);
mExchangeACL = nullptr;
}

#if defined(CHIP_EXCHANGE_CONTEXT_DETAIL_LOGGING)
ChipLogProgress(ExchangeManager, "ec-- id: %d [%04" PRIX16 "], inUse: %d, addr: 0x%x", (this - em->ContextPool + 1),
mExchangeId, em->GetContextsInUse(), this);
#endif
SYSTEM_STATS_DECREMENT(chip::System::Stats::kExchangeMgr_NumContexts);
}

bool ExchangeContext::MatchExchange(SecureSessionHandle session, const PacketHeader & packetHeader,
const PayloadHeader & payloadHeader)
{
Expand Down
1 change: 0 additions & 1 deletion src/messaging/ExchangeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext,
ExchangeDelegateBase * delegate);
void Free();
void Reset();
void ForceFree();

void SetResponseTimeout(Timeout timeout);

Expand Down
7 changes: 2 additions & 5 deletions src/messaging/ExchangeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ CHIP_ERROR ExchangeManager::Shutdown()

for (auto & ec : mContextPool)
{
if (ec.GetReferenceCount() > 0)
{
ChipLogError(ExchangeManager, "Exchange (id: %d) leaked", ec.GetExchangeId());
ec.ForceFree();
}
// ExchangeContext leaked
assert(ec.GetReferenceCount() == 0);
}

if (mSessionMgr != nullptr)
Expand Down

0 comments on commit a0639a7

Please sign in to comment.