Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP][1.3][IM]Fix leaked readClient in onFabricRemoved call #37265

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,12 +1864,20 @@ void InteractionModelEngine::OnFabricRemoved(const FabricTable & fabricTable, Fa
});

#if CHIP_CONFIG_ENABLE_READ_CLIENT
for (auto * readClient = mpActiveReadClientList; readClient != nullptr; readClient = readClient->GetNextClient())
for (auto * readClient = mpActiveReadClientList; readClient != nullptr;)
{
// ReadClient::Close may delete the read client so that readClient->GetNextClient() will be use-after-free.
// We need save readClient as nextReadClient before closing.
if (readClient->GetFabricIndex() == fabricIndex)
{
ChipLogProgress(InteractionModel, "Fabric removed, deleting obsolete read client with FabricIndex: %u", fabricIndex);
auto * nextReadClient = readClient->GetNextClient();
readClient->Close(CHIP_ERROR_IM_FABRIC_DELETED, false);
readClient = nextReadClient;
}
else
{
readClient = readClient->GetNextClient();
}
}
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT
Expand Down
2 changes: 1 addition & 1 deletion src/app/InteractionModelEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
bool mSubscriptionResumptionScheduled = false;
#endif

FabricTable * mpFabricTable;
FabricTable * mpFabricTable = nullptr;

CASESessionManager * mpCASESessionMgr = nullptr;

Expand Down
Loading