diff --git a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp index 692bc535..94df06b3 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.cpp @@ -621,7 +621,7 @@ void JsInputMethodEngineSetting::OnInputStop() return; } IMSA_HILOGI("run in"); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -631,6 +631,7 @@ void JsInputMethodEngineSetting::OnInputStop() JsCallbackHandler::Traverse(entry->vecCopy); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsInputMethodEngineSetting::OnSetCallingWindow(uint32_t windowId) @@ -670,7 +671,7 @@ void JsInputMethodEngineSetting::OnSetSubtype(const SubProperty &property) return; } IMSA_HILOGI("subtypeId: %{public}s", property.id.c_str()); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -698,6 +699,7 @@ void JsInputMethodEngineSetting::OnSetSubtype(const SubProperty &property) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getSubtypeProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsInputMethodEngineSetting::OnSecurityChange(int32_t security) @@ -709,7 +711,7 @@ void JsInputMethodEngineSetting::OnSecurityChange(int32_t security) return; } IMSA_HILOGI("run in: %{public}s", type.c_str()); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -732,6 +734,7 @@ void JsInputMethodEngineSetting::OnSecurityChange(int32_t security) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getSecurityProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } uv_work_t *JsInputMethodEngineSetting::GetUVwork(const std::string &type, EntrySetter entrySetter) @@ -794,5 +797,17 @@ std::shared_ptr JsInputMethodEngineSetting: } return entry; } + +void JsInputMethodEngineSetting::FreeWorkIfFail(int ret, uv_work_t *work) +{ + if (ret == 0 || work == nullptr) { + return; + } + + UvEntry *data = static_cast(work->data); + delete data; + delete work; + IMSA_HILOGE("uv_queue_work failed retCode:%{public}d", ret); +} } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h index 99bec4b8..8c660d42 100644 --- a/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h +++ b/frameworks/js/napi/inputmethodability/js_input_method_engine_setting.h @@ -111,6 +111,7 @@ private: static std::shared_ptr GetEventHandler(); std::shared_ptr GetEntry(const std::string &type, EntrySetter entrySetter = nullptr); uv_work_t *GetUVwork(const std::string &type, EntrySetter entrySetter = nullptr); + void FreeWorkIfFail(int ret, uv_work_t *work); uv_loop_s *loop_ = nullptr; std::recursive_mutex mutex_; std::map>> jsCbMap_; diff --git a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp index 566413f0..857d0740 100644 --- a/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp +++ b/frameworks/js/napi/inputmethodability/js_keyboard_delegate_setting.cpp @@ -553,7 +553,7 @@ void JsKeyboardDelegateSetting::OnTextChange(const std::string &text) return; } IMSA_HILOGI("run in"); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -573,6 +573,12 @@ void JsKeyboardDelegateSetting::OnTextChange(const std::string &text) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getTextChangeProperty }); }, uv_qos_user_initiated); + if (ret != 0) { + IMSA_HILOGE("uv_queue_work failed retCode:%{public}d", ret); + UvEntry *data = static_cast(work->data); + delete data; + delete work; + } } void JsKeyboardDelegateSetting::OnEditorAttributeChange(const InputAttribute &inputAttribute) diff --git a/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp b/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp index 563ad232..8e80dda8 100644 --- a/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp +++ b/frameworks/js/napi/inputmethodability/panel_listener_impl.cpp @@ -92,7 +92,7 @@ void PanelListenerImpl::OnPanelStatus(uint32_t windowId, bool isShow) uv_loop_s *loop = nullptr; napi_get_uv_event_loop(callback.second->env_, &loop); IMSA_HILOGI("windowId = %{public}u, type = %{public}s", windowId, type.c_str()); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -106,6 +106,12 @@ void PanelListenerImpl::OnPanelStatus(uint32_t windowId, bool isShow) JsCallbackHandler::Traverse({ entry->cbCopy }); }, uv_qos_user_initiated); + if (ret != 0) { + IMSA_HILOGE("uv_queue_work failed retCode:%{public}d", ret); + UvEntry *data = static_cast(work->data); + delete data; + delete work; + } } } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp index 362db7f0..10ca90f6 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.cpp @@ -707,7 +707,7 @@ void JsGetInputMethodController::OnSelectByRange(int32_t start, int32_t end) return; } IMSA_HILOGI("start: %{public}d, end: %{public}d", start, end); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -735,6 +735,7 @@ void JsGetInputMethodController::OnSelectByRange(int32_t start, int32_t end) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodController::OnSelectByMovement(int32_t direction) @@ -746,7 +747,7 @@ void JsGetInputMethodController::OnSelectByMovement(int32_t direction) return; } IMSA_HILOGI("direction: %{public}d", direction); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -774,6 +775,7 @@ void JsGetInputMethodController::OnSelectByMovement(int32_t direction) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodController::InsertText(const std::u16string &text) @@ -786,7 +788,7 @@ void JsGetInputMethodController::InsertText(const std::u16string &text) return; } IMSA_HILOGI("run in"); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -811,6 +813,7 @@ void JsGetInputMethodController::InsertText(const std::u16string &text) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getInsertTextProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodController::DeleteRight(int32_t length) @@ -822,7 +825,7 @@ void JsGetInputMethodController::DeleteRight(int32_t length) return; } IMSA_HILOGI("length: %{public}d", length); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -847,6 +850,7 @@ void JsGetInputMethodController::DeleteRight(int32_t length) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getDeleteForwardProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodController::DeleteLeft(int32_t length) @@ -858,7 +862,7 @@ void JsGetInputMethodController::DeleteLeft(int32_t length) return; } IMSA_HILOGI("length: %{public}d", length); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -883,6 +887,7 @@ void JsGetInputMethodController::DeleteLeft(int32_t length) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getDeleteBackwardProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodController::SendKeyboardStatus(const KeyboardStatus &status) @@ -895,7 +900,7 @@ void JsGetInputMethodController::SendKeyboardStatus(const KeyboardStatus &status return; } IMSA_HILOGI("status: %{public}d", static_cast(status)); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -920,6 +925,7 @@ void JsGetInputMethodController::SendKeyboardStatus(const KeyboardStatus &status JsCallbackHandler::Traverse(entry->vecCopy, { 1, getSendKeyboardStatusProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } napi_value JsGetInputMethodController::CreateSendFunctionKey(napi_env env, int32_t functionKey) @@ -944,7 +950,7 @@ void JsGetInputMethodController::SendFunctionKey(const FunctionKey &functionKey) return; } IMSA_HILOGI("functionKey: %{public}d", static_cast(functionKey.GetEnterKeyType())); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -974,6 +980,7 @@ void JsGetInputMethodController::SendFunctionKey(const FunctionKey &functionKey) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getSendFunctionKeyProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodController::MoveCursor(const Direction direction) @@ -986,7 +993,7 @@ void JsGetInputMethodController::MoveCursor(const Direction direction) return; } IMSA_HILOGI("direction: %{public}d", static_cast(direction)); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -1011,6 +1018,7 @@ void JsGetInputMethodController::MoveCursor(const Direction direction) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getMoveCursorProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodController::HandleExtendAction(int32_t action) @@ -1022,7 +1030,7 @@ void JsGetInputMethodController::HandleExtendAction(int32_t action) return; } IMSA_HILOGI("action: %{public}d", action); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -1046,6 +1054,7 @@ void JsGetInputMethodController::HandleExtendAction(int32_t action) JsCallbackHandler::Traverse(entry->vecCopy, { 1, getHandleExtendActionProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } std::u16string JsGetInputMethodController::GetText(const std::string &type, int32_t number) @@ -1060,7 +1069,7 @@ std::u16string JsGetInputMethodController::GetText(const std::string &type, int3 return u""; } IMSA_HILOGI("type: %{public}s, number: %{public}d", type.c_str(), number); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -1086,6 +1095,7 @@ std::u16string JsGetInputMethodController::GetText(const std::string &type, int3 entry->textResultHandler->SetValue(text); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); return Str8ToStr16(textResultHandler->GetValue()); } @@ -1100,7 +1110,7 @@ int32_t JsGetInputMethodController::GetTextIndexAtCursor() return -1; } IMSA_HILOGI("run in"); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -1117,6 +1127,7 @@ int32_t JsGetInputMethodController::GetTextIndexAtCursor() entry->indexResultHandler->SetValue(index); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); return indexResultHandler->GetValue(); } @@ -1149,5 +1160,17 @@ uv_work_t *JsGetInputMethodController::GetUVwork(const std::string &type, EntryS work->data = entry; return work; } + +void JsGetInputMethodController::FreeWorkIfFail(int ret, uv_work_t *work) +{ + if (ret == 0 || work == nullptr) { + return; + } + + UvEntry *data = static_cast(work->data); + delete data; + delete work; + IMSA_HILOGE("uv_queue_work failed retCode:%{public}d", ret); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h index 1505fd47..cd99f579 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_controller.h @@ -228,6 +228,7 @@ private: }; using EntrySetter = std::function; uv_work_t *GetUVwork(const std::string &type, EntrySetter entrySetter = nullptr); + void FreeWorkIfFail(int ret, uv_work_t *work); uv_loop_s *loop_ = nullptr; std::recursive_mutex mutex_; std::map>> jsCbMap_; diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp index abcac98c..7c398cef 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp @@ -586,7 +586,7 @@ void JsGetInputMethodSetting::OnImeChange(const Property &property, const SubPro return; } IMSA_HILOGI("run in"); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -617,6 +617,7 @@ void JsGetInputMethodSetting::OnImeChange(const Property &property, const SubPro JsCallbackHandler::Traverse(entry->vecCopy, { 2, getImeChangeProperty }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } void JsGetInputMethodSetting::OnPanelStatusChange( @@ -634,7 +635,7 @@ void JsGetInputMethodSetting::OnPanelStatusChange( return; } IMSA_HILOGI("status: %{public}u", static_cast(status)); - uv_queue_work_with_qos( + auto ret = uv_queue_work_with_qos( loop_, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { std::shared_ptr entry(static_cast(work->data), [work](UvEntry *data) { @@ -662,6 +663,7 @@ void JsGetInputMethodSetting::OnPanelStatusChange( JsCallbackHandler::Traverse(entry->vecCopy, { 1, getWindowInfo }); }, uv_qos_user_initiated); + FreeWorkIfFail(ret, work); } uv_work_t *JsGetInputMethodSetting::GetUVwork(const std::string &type, EntrySetter entrySetter) @@ -693,5 +695,16 @@ uv_work_t *JsGetInputMethodSetting::GetUVwork(const std::string &type, EntrySett work->data = entry; return work; } +void JsGetInputMethodSetting::FreeWorkIfFail(int ret, uv_work_t *work) +{ + if (ret == 0 || work == nullptr) { + return; + } + + UvEntry *data = static_cast(work->data); + delete data; + delete work; + IMSA_HILOGE("uv_queue_work failed retCode:%{public}d", ret); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h index 35c730c5..4db30b70 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h @@ -136,6 +136,7 @@ private: }; using EntrySetter = std::function; uv_work_t *GetUVwork(const std::string &type, EntrySetter entrySetter = nullptr); + void FreeWorkIfFail(int ret, uv_work_t *work); static const std::string IMS_CLASS_NAME; static thread_local napi_ref IMSRef_; uv_loop_s *loop_ = nullptr;