From 86ebb3972bd427ad18fad2940540c99938021180 Mon Sep 17 00:00:00 2001 From: blc Date: Thu, 17 Jul 2025 20:03:57 +0800 Subject: [PATCH] fix OnConnectSystemCmd crash Signed-off-by: blc --- .../src/input_method_ability.cpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index b05eff733..d4c0daaf7 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -999,21 +999,22 @@ sptr InputMethodAbility::GetSystemCmdChannelProxy() int32_t InputMethodAbility::OnConnectSystemCmd(const sptr &channel, sptr &agent) { IMSA_HILOGD("InputMethodAbility start."); - { - std::lock_guard lock(systemCmdChannelLock_); - systemCmdChannelProxy_ = new (std::nothrow) SystemCmdChannelProxy(channel); - if (systemCmdChannelProxy_ == nullptr) { - IMSA_HILOGE("failed to create channel proxy!"); - return ErrorCode::ERROR_CLIENT_NULL_POINTER; - } - } - systemAgentStub_ = new (std::nothrow) InputMethodAgentServiceImpl(); - if (systemAgentStub_ == nullptr) { + sptr agentImpl = new (std::nothrow) InputMethodAgentServiceImpl(); + if (agentImpl == nullptr) { IMSA_HILOGE("failed to create agent!"); - systemCmdChannelProxy_ = nullptr; return ErrorCode::ERROR_CLIENT_NULL_POINTER; } - agent = systemAgentStub_->AsObject(); + sptr cmdChannel = new (std::nothrow) SystemCmdChannelProxy(channel); + if (cmdChannel == nullptr) { + IMSA_HILOGE("failed to create channel proxy!"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; + } + { + std::lock_guard lock(systemCmdChannelLock_); + systemCmdChannelProxy_ = cmdChannel; + systemAgentStub_ = agentImpl; + } + agent = agentImpl->AsObject(); auto panel = GetSoftKeyboardPanel(); if (panel != nullptr) { auto flag = panel->GetPanelFlag(); -- Gitee