smartdevicelink / sdl_core

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

Do not modify application list while iterating it #3806

Closed iCollin closed 2 years ago

iCollin commented 2 years ago

Fixes https://github.com/smartdevicelink/sdl_core/issues/3805 (crash in UI lang change) Fixes https://github.com/smartdevicelink/sdl_core/issues/3783 (crash in VR lang change)

Reverts https://github.com/smartdevicelink/sdl_core/pull/3796 (alternate fix for VR lang change crash) Therefore Fixes https://github.com/smartdevicelink/sdl_core/issues/3674 (regression caused by 3796) (also reverts part of https://github.com/smartdevicelink/sdl_core/pull/3799, a fixup to 3796)

This PR is ready for review.

Risk

This PR makes no API changes.

Testing Plan

https://github.com/smartdevicelink/sdl_atf_test_scripts/pull/2602 3674_1_HMI_sends_OnSystemRequest_before_UpdateAppList.lua (many iterations) https://github.com/smartdevicelink/sdl_atf_test_scripts/pull/2603 3797_3798_HMI_sends_SetAppProperties_and_tries_to_ActivateApp.lua

Summary

Core was modifying applications array while iterating it during language change, now we are iterating copies that won't be modified while iterating them.

Also a crash was noticed and fixed by https://github.com/smartdevicelink/sdl_core/pull/3806/commits/8be17f5cfd3350e712b52e0b3be583ace57e580a

Thread 8 "AM Pool 0" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff0a91700 (LWP 100005)]
0x00007fffe87559ab in sdl_rpc_plugin::commands::RegisterAppInterfaceResponse::Run (this=0x7fff900483d0) at /home/collin/core/builds/dev_no_log/sdl_core/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_response.cc:100
100     app->set_is_ready(true);
#0  0x00007fffe87559ab in sdl_rpc_plugin::commands::RegisterAppInterfaceResponse::Run (this=0x7fff900483d0) at /home/collin/core/builds/dev_no_log/sdl_core/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/register_app_interface_response.cc:100
        result_code = mobile_apis::Result::SUCCESS
        success = true
        last_message = false
        app = std::shared_ptr<application_manager::Application> (empty) = {get() = 0x0}
        event = {_vptr.MobileEvent = 0xf0a90620, id_ = -257357840, response_so_ = {m_type = 1476598128, m_data = {double_value = 6.9533430926564036e-310, bool_value = false, char_value = 0 '\000', int_value = 140737230997248, str_value = 0x7ffff0a90700, array_value = 0x7ffff0a90700, map_value = 0x7ffff0a90700, binary_value = 0x7ffff0a90700}, m_schema = {mSchemaItem = <error reading variable: Cannot access memory at address 0x45228a11cb85f608>}}}
        event_msg = {m_type = -382494360, m_data = {double_value = 6.9533369100995419e-310, bool_value = 40, char_value = 40 '(', int_value = 140737105860904, str_value = 0x7fffe9339928, array_value = 0x7fffe9339928, map_value = 0x7fffe9339928, binary_value = 0x7fffe9339928}, m_schema = {mSchemaItem = std::shared_ptr<ns_smart_device_link::ns_smart_objects::ISchemaItem> (use count 473122916, weak count 10276) = {get() = 0x7ffff0a90640}}}
#1  0x00005555562ee8c3 in application_manager::rpc_service::RPCServiceImpl::ManageMobileCommand (this=0x555557a8d350, message=std::shared_ptr<ns_smart_device_link::ns_smart_objects::SmartObject> (use count 4, weak count 0) = {...}, source=application_manager::commands::Command::SOURCE_SDL, warning_info="") at /home/collin/core/builds/dev_no_log/sdl_core/src/components/application_manager/src/rpc_service_impl.cc:225
        connection_key = 65537
        window_id = 0
        message_type = 1
        app_ptr = std::shared_ptr<application_manager::Application> (empty) = {get() = 0x0}

CLA