@@ -1844,13 +1844,25 @@ void DeviceCommissioner::CleanupCommissioning(DeviceProxy * proxy, NodeId nodeId
1844
1844
1845
1845
if (completionStatus.err == CHIP_NO_ERROR)
1846
1846
{
1847
+ // CommissioningStageComplete uses mDeviceBeingCommissioned, which can
1848
+ // be commissionee if we are cleaning up before we've gone operational. Normally
1849
+ // that would not happen in this non-error case, _except_ if we were told to skip sending
1850
+ // CommissioningComplete: in that case we do not have an operational DeviceProxy, so
1851
+ // we're using our CommissioneeDeviceProxy to do a successful cleanup.
1852
+ //
1853
+ // This means we have to call CommissioningStageComplete() before we destroy commissionee.
1854
+ //
1855
+ // This should be safe, because CommissioningStageComplete() does not call CleanupCommissioning
1856
+ // when called in the cleanup stage (which is where we are), and StopPairing does not directly release
1857
+ // mDeviceBeingCommissioned.
1858
+ CommissioningStageComplete (CHIP_NO_ERROR);
1859
+
1847
1860
CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice (nodeId);
1848
1861
if (commissionee != nullptr )
1849
1862
{
1850
1863
ReleaseCommissioneeDevice (commissionee);
1851
1864
}
1852
1865
// Send the callbacks, we're done.
1853
- CommissioningStageComplete (CHIP_NO_ERROR);
1854
1866
SendCommissioningCompleteCallbacks (nodeId, mCommissioningCompletionStatus );
1855
1867
}
1856
1868
else if (completionStatus.err == CHIP_ERROR_CANCELLED)
@@ -1929,12 +1941,13 @@ void DeviceCommissioner::CleanupDoneAfterError()
1929
1941
VerifyOrReturn (mDeviceBeingCommissioned != nullptr );
1930
1942
1931
1943
NodeId nodeId = mDeviceBeingCommissioned ->GetDeviceId ();
1932
- // At this point, we also want to close off the pase session so we need to re-establish
1933
- CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice (nodeId);
1934
1944
1935
1945
// Signal completion - this will reset mDeviceBeingCommissioned.
1936
1946
CommissioningStageComplete (CHIP_NO_ERROR);
1937
1947
1948
+ // At this point, we also want to close off the pase session so we need to re-establish
1949
+ CommissioneeDeviceProxy * commissionee = FindCommissioneeDevice (nodeId);
1950
+
1938
1951
// If we've disarmed the failsafe, it's because we're starting again, so kill the pase connection.
1939
1952
if (commissionee != nullptr )
1940
1953
{
0 commit comments