diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 6288aa7f27d1a38209374d02234332f0a84f59bd..9242563b323f61c3ecec9dba2e9987e271f26f56 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -1037,7 +1037,9 @@ void InputHub::CloseDeviceLocked(Device &device) { std::lock_guard devicesLock(devicesMutex_); closingDevices_.push_back(std::move(devices_[device.path])); - devices_.erase(device.path); + if (devices_.find(device.path) != devices_.end()) { + devices_.erase(device.path); + } } } @@ -1049,7 +1051,9 @@ void InputHub::CloseDeviceForAllLocked(Device &device) UnregisterDeviceFromEpollLocked(device); device.Close(); closingDevices_.push_back(std::move(devices_[device.path])); - devices_.erase(device.path); + if (devices_.find(device.path) != devices_.end()) { + devices_.erase(device.path); + } } int32_t InputHub::UnregisterDeviceFromEpollLocked(const Device &device) const diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index 31c6f1d4c348df2d8864c8b7111c720544bd77a6..c7a7f154556ac6230548fdd2c0f422cc4dfc8efe 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -268,6 +268,10 @@ int32_t WhiteListUtil::ClearWhiteList(const std::string &deviceId) DHLOGI("deviceId=%{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(mutex_); + if (mapDeviceWhiteList_.find(deviceId) == mapDeviceWhiteList_.end()) { + DHLOGE("The deviceId is not exist"); + return ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST; + } mapDeviceWhiteList_.erase(deviceId); return DH_SUCCESS; } diff --git a/services/state/src/dinput_sink_state.cpp b/services/state/src/dinput_sink_state.cpp index 8bf357f70d384bc8ec803c8462daf30ab06940e1..91a39abb56634477f0c05a583d65882e04bc4460 100644 --- a/services/state/src/dinput_sink_state.cpp +++ b/services/state/src/dinput_sink_state.cpp @@ -77,7 +77,9 @@ int32_t DInputSinkState::RemoveDhIds(const std::vector &dhIds) std::lock_guard mapLock(operationMutex_); for (const auto &dhid : dhIds) { DHLOGD("delete dhid : %{public}s", GetAnonyString(dhid).c_str()); - dhIdStateMap_.erase(dhid); + if (dhIdStateMap_.find(dhid) != dhIdStateMap_.end()) { + dhIdStateMap_.erase(dhid); + } } return DH_SUCCESS; } diff --git a/services/state/src/touchpad_event_fragment_mgr.cpp b/services/state/src/touchpad_event_fragment_mgr.cpp index de4427176fcce3ed2dcd2c229859a58801d94def..65146ad3788b829e3115deef95f58a1602179dc8 100644 --- a/services/state/src/touchpad_event_fragment_mgr.cpp +++ b/services/state/src/touchpad_event_fragment_mgr.cpp @@ -91,6 +91,10 @@ std::pair> TouchPadEventFragmentMgr::DealSynEvent(co void TouchPadEventFragmentMgr::Clear(const std::string &dhId) { std::lock_guard lock(fragmentsMtx_); + if (fragments_.find(dhId) == fragments_.end()) { + DHLOGE("The dhId is not exist"); + return; + } fragments_.erase(dhId); } diff --git a/services/transportbase/src/distributed_input_transport_base.cpp b/services/transportbase/src/distributed_input_transport_base.cpp index ad8a335471226f235cfdfdb62effb286879e57e3..ffa98088ba0d5909cf1f411ef17edeffbb1e388f 100644 --- a/services/transportbase/src/distributed_input_transport_base.cpp +++ b/services/transportbase/src/distributed_input_transport_base.cpp @@ -304,7 +304,9 @@ void DistributedInputTransportBase::StopSession(const std::string &remoteDevId) HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::CLOSING); Shutdown(sessionId); remoteDevSessionMap_.erase(remoteDevId); - channelStatusMap_.erase(remoteDevId); + if (channelStatusMap_.find(remoteDevId) != channelStatusMap_.end()) { + channelStatusMap_.erase(remoteDevId); + } std::shared_ptr dhFwkKit = DInputContext::GetInstance().GetDHFwkKit(); if (dhFwkKit != nullptr) { @@ -413,7 +415,9 @@ void DistributedInputTransportBase::OnSessionClosed(int32_t sessionId, ShutdownR if (CountSession(deviceId) > 0) { EraseSessionId(deviceId); } - channelStatusMap_.erase(deviceId); + if (channelStatusMap_.find(deviceId) != channelStatusMap_.end()) { + channelStatusMap_.erase(deviceId); + } if (sinkCallback_ == nullptr) { DHLOGE("sinkCallback is nullptr."); diff --git a/utils/src/dinput_context.cpp b/utils/src/dinput_context.cpp index b7226c63ad37c4a03c180bd9a56104c1eea12691..c505f269ea324fbcb745a678152ba385b7bb47e9 100644 --- a/utils/src/dinput_context.cpp +++ b/utils/src/dinput_context.cpp @@ -42,6 +42,10 @@ int32_t DInputContext::RemoveSinkScreenInfo(const std::string &screenInfoKey) { DHLOGI("RemoveSinkScreenInfo screenInfoKey: %{public}s", GetAnonyString(screenInfoKey).c_str()); std::lock_guard lock(sinkMapMutex_); + if (sinkScreenInfoMap_.find(screenInfoKey) == sinkScreenInfoMap_.end()) { + DHLOGE("The screenInfoKey is not exist"); + return ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST; + } sinkScreenInfoMap_.erase(screenInfoKey); return DH_SUCCESS; } @@ -87,6 +91,10 @@ int32_t DInputContext::RemoveSrcScreenInfo(const std::string &screenInfoKey) { DHLOGI("RemoveSrcScreenInfo screenInfoKey: %{public}s", GetAnonyString(screenInfoKey).c_str()); std::lock_guard lock(srcMapMutex_); + if (srcScreenInfoMap_.find(screenInfoKey) == srcScreenInfoMap_.end()) { + DHLOGE("The screenInfoKey is not exist"); + return ERR_DH_INPUT_CONTEXT_KEY_NOT_EXIST; + } srcScreenInfoMap_.erase(screenInfoKey); return DH_SUCCESS; } @@ -205,6 +213,10 @@ void DInputContext::AddRemoteObject(const int32_t saId, const sptr lock(remoteObjectsMutex_); + if (remoteObjects_.find(saId) == remoteObjects_.end()) { + DHLOGE("The saId: %{public}d is not exist", saId); + return; + } remoteObjects_.erase(saId); } } // namespace DistributedInput