Skip to content

Commit

Permalink
Fix System vs Inet and BLE shutdown order (#7429)
Browse files Browse the repository at this point in the history
#### 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).
  • Loading branch information
kpschoedel authored and pull[bot] committed Jul 29, 2021
1 parent fa1e141 commit 1178668
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ CHIP_ERROR DeviceController::Shutdown()
#if CONFIG_DEVICE_LAYER
ReturnErrorOnFailure(DeviceLayer::PlatformMgr().Shutdown());
#else
mSystemLayer->Shutdown();
mInetLayer->Shutdown();
chip::Platform::Delete(mSystemLayer);
mSystemLayer->Shutdown();
chip::Platform::Delete(mInetLayer);
chip::Platform::Delete(mSystemLayer);
#endif // CONFIG_DEVICE_LAYER

mSystemLayer = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ void JNI_OnUnload(JavaVM * jvm, void * reserved)
sBleLayer.Shutdown();
#endif

sSystemLayer.Shutdown();
sInetLayer.Shutdown();
sSystemLayer.Shutdown();
sJVM = NULL;

chip::Platform::MemoryShutdown();
Expand Down
6 changes: 4 additions & 2 deletions src/include/platform/internal/GenericPlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ template <class ImplClass>
CHIP_ERROR GenericPlatformManagerImpl<ImplClass>::_Shutdown()
{
CHIP_ERROR err;
ChipLogError(DeviceLayer, "System Layer shutdown");
err = SystemLayer.Shutdown();
ChipLogError(DeviceLayer, "Inet Layer shutdown");
err = InetLayer.Shutdown();

#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
ChipLogError(DeviceLayer, "BLE layer shutdown");
err = BLEMgr().GetBleLayer()->Shutdown();
#endif

ChipLogError(DeviceLayer, "System Layer shutdown");
err = SystemLayer.Shutdown();

return err;
}

Expand Down

0 comments on commit 1178668

Please sign in to comment.