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

Fix crashes when DeviceCommissioner is shut down. #22245

Merged
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
20 changes: 20 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,17 @@ void DeviceCommissioner::Shutdown()
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY

// If we have a commissionee device for the device being commissioned,
// release it now, before we release our whole commissionee pool.
if (mDeviceBeingCommissioned != nullptr)
{
auto * commissionee = FindCommissioneeDevice(mDeviceBeingCommissioned->GetDeviceId());
Damian-Nordic marked this conversation as resolved.
Show resolved Hide resolved
if (commissionee)
{
ReleaseCommissioneeDevice(commissionee);
}
}

// Release everything from the commissionee device pool here. DeviceController::Shutdown releases operational.
mCommissioneeDevicePool.ReleaseAll();

Expand Down Expand Up @@ -1561,6 +1572,15 @@ void DeviceCommissioner::CommissioningStageComplete(CHIP_ERROR err, Commissionin
{
// Once this stage is complete, reset mDeviceBeingCommissioned - this will be reset when the delegate calls the next step.
MATTER_TRACE_EVENT_SCOPE("CommissioningStageComplete", "DeviceCommissioner");

if (mDeviceBeingCommissioned == nullptr)
{
// We are getting a stray callback (e.g. due to un-cancellable
// operations) when we are not in fact commissioning anything. Just
// ignore it.
return;
}

NodeId nodeId = mDeviceBeingCommissioned->GetDeviceId();
DeviceProxy * proxy = mDeviceBeingCommissioned;
mDeviceBeingCommissioned = nullptr;
Expand Down