Skip to content

Commit

Permalink
CP [IM]Fix leaked readClient in onFabricRemoved call (project-chip#37265
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yunhanw-google authored Jan 28, 2025
1 parent 593d5c6 commit 518c012
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit 518c012

Please sign in to comment.