Skip to content

Commit

Permalink
Fix crashes when DeviceCommissioner is shut down. (project-chip#22245)
Browse files Browse the repository at this point in the history
There are two fixes here:

1) Ensure that DeviceCommissioner::Shutdown properly cleans up
   mDeviceBeingCommissioned so we don't end up with it being a dangling pointer.

2) Ensure that DeviceCommissioner::CommissioningStageComplete doesn't try to
   derefence a null mDeviceBeingCommissioned (which indicates something has
   already stopped the commissioning process).

Fixes project-chip#22243
  • Loading branch information
bzbarsky-apple authored and isiu-apple committed Sep 16, 2022
1 parent f60dd87 commit ac8524e
Showing 1 changed file with 20 additions and 0 deletions.
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());
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

0 comments on commit ac8524e

Please sign in to comment.