From 33dcbbae4c720d344eede851662702bc5708a3bf Mon Sep 17 00:00:00 2001 From: zhaolinglan Date: Thu, 21 Jul 2022 09:57:52 +0800 Subject: [PATCH] modify two files at 7/21 09:57 Signed-off-by: zhaolinglan --- .../src/js_input_method_engine_listener.cpp | 12 ++++++++++-- services/src/input_method_system_ability_stub.cpp | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp index b134ad1..305c6bb 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_input_method_engine_listener.cpp @@ -64,10 +64,18 @@ namespace MiscServices { // should do type check std::lock_guard lk(mapMutex); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - IMSA_HILOGI("methodName %{public}s not registerted!", type.c_str()); + IMSA_HILOGI("methodName %{public}s not registered!", type.c_str()); return; } - jsCbMap_.erase(type); + for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) { + if (value->StrictEquals((*it)->Get())) { + jsCbMap_[type].erase(it); + break; + } + } + if (jsCbMap_[type].empty()) { + jsCbMap_.erase(type); + } } bool JsInputMethodEngineListener::IfCallbackRegistered(std::string type, NativeValue* jsListenerObject) diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index 63e0b5d..029aecb 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -316,6 +316,9 @@ namespace MiscServices { int32_t userId = getUserId(uid); auto *parcel = new (std::nothrow) MessageParcel(); + if (parcel == nullptr) { + return ErrorCode::ERROR_EX_NULL_POINTER; + } InputMethodProperty *target = InputMethodProperty::Unmarshalling(data); parcel->WriteInt32(userId); if (!target->Marshalling(*parcel)) { @@ -326,6 +329,9 @@ namespace MiscServices { } delete target; auto *msg = new (std::nothrow) Message(MSG_ID_SWITCH_INPUT_METHOD, parcel); + if (msg == nullptr) { + return ErrorCode::ERROR_EX_NULL_POINTER; + } MessageHandler::Instance()->SendMessage(msg); return ErrorCode::NO_ERROR; }