diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 37691a6f08879b438716a5f91f8139bbe1897f76..5f941182b213a14713a9b202f4c4c73e7a49d1ad 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -104,6 +104,10 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, SEN_HILOGE("sensorTypeId not in g_subscribeMap"); return; } + if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { + SEN_HILOGE("sensor user is null"); + return; + } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); } } diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index e59d414c2f271323b2443464c86abb17186d9e2c..bf0cc9b5fbf47cec71e0964f77a40934ce471314 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -131,7 +131,10 @@ bool SensorService::InitSensorList() { std::lock_guard sensorMapLock(sensorMapMutex_); for (const auto &it : sensors_) { - sensorMap_.insert(std::make_pair(it.GetSensorId(), it)); + if (!(sensorMap_.insert(std::make_pair(it.GetSensorId(), it)).second)) { + HiLog::Warn(LABEL, "%{public}s sensorMap_ Insert failed", __func__); + return false; + } } } return true;