Skip to content

Commit 1178668

Browse files
kpschoedelpull[bot]
authored andcommitted
Fix System vs Inet and BLE shutdown order (#7429)
#### Problem Inet and BLE contain pointers to the System::Layer, but in some implementations System::Layer is shut down first, leaving those pointers invalid. (There appear to be no current uses of those invalid pointers in the tree.) #### Change overview Shut down system layer after the others in: - `DeviceController::Shutdown()` - `GenericPlatformManagerImpl::_Shutdown()` - `JNI_OnUnload()` #### Testing - Some existing unit tests use the correct order (System last), so it's known to work. - Manually tested with platforms using `GenericPlatformManagerImpl::_Shutdown()` (Linux paired with ESP32).
1 parent fa1e141 commit 1178668

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/controller/CHIPDeviceController.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ CHIP_ERROR DeviceController::Shutdown()
307307
#if CONFIG_DEVICE_LAYER
308308
ReturnErrorOnFailure(DeviceLayer::PlatformMgr().Shutdown());
309309
#else
310-
mSystemLayer->Shutdown();
311310
mInetLayer->Shutdown();
312-
chip::Platform::Delete(mSystemLayer);
311+
mSystemLayer->Shutdown();
313312
chip::Platform::Delete(mInetLayer);
313+
chip::Platform::Delete(mSystemLayer);
314314
#endif // CONFIG_DEVICE_LAYER
315315

316316
mSystemLayer = nullptr;

src/controller/java/CHIPDeviceController-JNI.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ void JNI_OnUnload(JavaVM * jvm, void * reserved)
229229
sBleLayer.Shutdown();
230230
#endif
231231

232-
sSystemLayer.Shutdown();
233232
sInetLayer.Shutdown();
233+
sSystemLayer.Shutdown();
234234
sJVM = NULL;
235235

236236
chip::Platform::MemoryShutdown();

src/include/platform/internal/GenericPlatformManagerImpl.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,17 @@ template <class ImplClass>
124124
CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_Shutdown()
125125
{
126126
CHIP_ERROR err;
127-
ChipLogError(DeviceLayer, "System Layer shutdown");
128-
err = SystemLayer.Shutdown();
129127
ChipLogError(DeviceLayer, "Inet Layer shutdown");
130128
err = InetLayer.Shutdown();
131129

132130
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
133131
ChipLogError(DeviceLayer, "BLE layer shutdown");
134132
err = BLEMgr().GetBleLayer()->Shutdown();
135133
#endif
134+
135+
ChipLogError(DeviceLayer, "System Layer shutdown");
136+
err = SystemLayer.Shutdown();
137+
136138
return err;
137139
}
138140

0 commit comments

Comments
 (0)