void gpsdataTimerCallBackproc()
{
- GraphicService::GetInstance()->PostGraphicEvent(std::bind(&testGPSView::gpsdataTimerCallBack,testGPSView::GetInstance()));
+ // 定时器是全局的,可能在界面已销毁后仍然触发一次,这里要做空指针防护
+ testGPSView *view = testGPSView::GetInstance();
+ if (view == nullptr) {
+ return;
+ }
+ GraphicService::GetInstance()->PostGraphicEvent(std::bind(&testGPSView::gpsdataTimerCallBack, view));
}
static testoldView *g_pSystemAboutTheWatchView{nullptr};
static osTimerId_t g_aging_timer=NULL;
-
+ static volatile bool g_aging_view_valid = false; /* 防止定时器回调在界面销毁后访问已释放控件导致 Load access fault */
+
#ifdef SUPPORT_FACTORY_SERVICE
static ble_aging_t aging_t;
#endif
{
if(testoldScrollView)
{
+ g_aging_view_valid = false;
testoldScrollView->RemoveAll();
if (g_aging_timer != NULL)
{
do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_AGING_DATA_READ, NULL, 0);
LOS_Msleep(500);
-#ifdef SUPPORT_FACTORY_SERVICE
+ if (!g_aging_view_valid) {
+ return; /* 界面已退出或正在清理,避免 use-after-free 导致 Load access fault */
+ }
factorytest_get_aging_data(&aging_t);
-#endif
OHOS::testoldView *pview = OHOS::testoldView::GetInstance();
+ if (pview == nullptr || !g_aging_view_valid) {
+ return;
+ }
pview->setdata();
}
testoldScrollView->SetTouchable(true);
testoldScrollView->SetDraggable(true);
+ g_aging_view_valid = true; /* 界面已就绪,允许定时器回调访问 UI */
g_aging_timer = osTimerNew((osTimerFunc_t)msgupdateTimerCallBack, osTimerPeriodic, NULL, NULL);
osStatus_t ret = osTimerStart(g_aging_timer, 1000 * 60 * 10);