diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index b15bbe567ec7db..8ff2753685f1a0 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -102,6 +102,12 @@ CHIP_ERROR ExchangeManager::Shutdown() mMessageCounterSyncMgr.Shutdown(); mReliableMessageMgr.Shutdown(); + for (auto & ec : mContextPool) + { + // ExchangeContext leaked + assert(ec.GetReferenceCount() == 0); + } + if (mSessionMgr != nullptr) { mSessionMgr->SetDelegate(nullptr); diff --git a/src/messaging/tests/BUILD.gn b/src/messaging/tests/BUILD.gn index 7191349fdfc50f..19fd5fb9bbb355 100644 --- a/src/messaging/tests/BUILD.gn +++ b/src/messaging/tests/BUILD.gn @@ -27,7 +27,6 @@ chip_test_suite("tests") { "MessagingContext.h", "TestChannel.cpp", "TestExchangeMgr.cpp", - "TestMessageCounterSyncMgr.cpp", "TestMessagingLayer.h", "TestReliableMessageProtocol.cpp", ] @@ -49,7 +48,6 @@ chip_test_suite("tests") { tests = [ "TestChannel", "TestExchangeMgr", - "TestMessageCounterSyncMgr", "TestReliableMessageProtocol", ] } diff --git a/src/messaging/tests/TestExchangeMgr.cpp b/src/messaging/tests/TestExchangeMgr.cpp index 9e181e87ed4d79..6a30ce4bdca45b 100644 --- a/src/messaging/tests/TestExchangeMgr.cpp +++ b/src/messaging/tests/TestExchangeMgr.cpp @@ -75,6 +75,7 @@ class MockAppDelegate : public ExchangeDelegate System::PacketBufferHandle buffer) override { IsOnMessageReceivedCalled = true; + ec->Close(); } void OnResponseTimeout(ExchangeContext * ec) override {} @@ -102,6 +103,9 @@ void CheckNewContextTest(nlTestSuite * inSuite, void * inContext) auto sessionLocalToPeer = ctx.GetSecureSessionManager().GetPeerConnectionState(ec2->GetSecureSession()); NL_TEST_ASSERT(inSuite, sessionLocalToPeer->GetPeerNodeId() == ctx.GetDestinationNodeId()); NL_TEST_ASSERT(inSuite, sessionLocalToPeer->GetPeerKeyID() == ctx.GetPeerKeyId()); + + ec1->Close(); + ec2->Close(); } void CheckUmhRegistrationTest(nlTestSuite * inSuite, void * inContext) @@ -157,8 +161,10 @@ void CheckExchangeMessages(nlTestSuite * inSuite, void * inContext) // send a good packet ec1->SendMessage(Protocols::Id(VendorId::Common, 0x0001), 0x0001, System::PacketBufferHandle::New(System::PacketBuffer::kMaxSize), - SendFlags(Messaging::SendMessageFlags::kNone)); + SendFlags(Messaging::SendMessageFlags::kNoAutoRequestAck)); NL_TEST_ASSERT(inSuite, mockUnsolicitedAppDelegate.IsOnMessageReceivedCalled); + + ec1->Close(); } // Test Suite diff --git a/src/messaging/tests/TestMessageCounterSyncMgr.cpp b/src/messaging/tests/TestMessageCounterSyncMgr.cpp index 7cac6980bb31d1..8391f6d7154fd8 100644 --- a/src/messaging/tests/TestMessageCounterSyncMgr.cpp +++ b/src/messaging/tests/TestMessageCounterSyncMgr.cpp @@ -158,6 +158,8 @@ class MockAppDelegate : public ExchangeDelegate NL_TEST_ASSERT(mSuite, packetHeader.GetSourceNodeId() == Optional::Value(kSourceNodeId)); NL_TEST_ASSERT(mSuite, packetHeader.GetDestinationNodeId() == Optional::Value(kDestinationNodeId)); NL_TEST_ASSERT(mSuite, msgBuf->DataLength() == kMsgCounterChallengeSize); + + ec->Close(); } void OnResponseTimeout(ExchangeContext * ec) override {} diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index 524d7b0cc8d752..7b602ba4384b54 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -124,6 +124,8 @@ void CheckAddClearRetrans(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 1); rm->ClearRetransTable(*entry); NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 0); + + exchange->Close(); } void CheckFailRetrans(nlTestSuite * inSuite, void * inContext) @@ -146,6 +148,8 @@ void CheckFailRetrans(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 1); rm->FailRetransTableEntries(rc, CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 0); + + exchange->Close(); } void CheckResendMessage(nlTestSuite * inSuite, void * inContext) @@ -192,6 +196,9 @@ void CheckResendMessage(nlTestSuite * inSuite, void * inContext) test_os_sleep_ms(65); ReliableMessageMgr::Timeout(&ctx.GetSystemLayer(), rm, CHIP_SYSTEM_NO_ERROR); NL_TEST_ASSERT(inSuite, gSendMessageCount == 3); + + rm->ClearRetransTable(rc); + exchange->Close(); } void CheckSendStandaloneAckMessage(nlTestSuite * inSuite, void * inContext) @@ -210,6 +217,8 @@ void CheckSendStandaloneAckMessage(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rc != nullptr); NL_TEST_ASSERT(inSuite, rc->SendStandaloneAckMessage() == CHIP_NO_ERROR); + + exchange->Close(); } // Test Suite