smartdevicelink / sdl_core

SmartDeviceLink In-Vehicle Software and Sample HMI
BSD 3-Clause "New" or "Revised" License
241 stars 244 forks source link

Fix for a potential SDL crash on boot #3581

Closed ychernysheva closed 3 years ago

ychernysheva commented 3 years ago

Fixes #3163

This PR is ready for review.

Risk

This PR makes no API changes.

Summary

One of the reasons why SDL is crashing on start is related to lazy initialization of the HMI/Mobile/v4 API classes. These classes are initialized on demand when some of threads are trying to get the object of that class first time. Most likely, at SDL start might be a situation when HMI/Mobile/v4 API classes are constructing in the one thread and at that moment another thread is trying to get access to the inner data of not-yet-fully-constructed object and this causes a core crash with ~ISchemaItem() calls in stack trace. That is possible because access to these factories is not synchronized.

To avoid such situation, factory creation was moved to AM ctor and all other sub components just use getters when they need to get access to API instances.

CLA

ychernysheva commented 3 years ago

@JackLivio This PR is ready for review. Thank you!