!2318 解决SoftBusClient对象存在引用,导致未按时销毁-同步5.0

Merge pull request !2318 from yanhui/cherry-pick-1727315576
This commit is contained in:
openharmony_ci 2024-09-27 09:42:51 +00:00 committed by Gitee
commit bc9fd9318d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 26 additions and 22 deletions

View File

@ -196,25 +196,24 @@ Status SoftBusAdapter::SendData(const PipeInfo &pipeInfo, const DeviceId &device
bool isOHOSType = DmAdapter::GetInstance().IsOHOSType(deviceId.deviceId);
uint32_t qosType = isOHOSType ? SoftBusClient::QOS_HML : SoftBusClient::QOS_BR;
bool isReuse = false;
connects_.Compute(deviceId.deviceId,
[&pipeInfo, &deviceId, &conn, qosType, isOHOSType, &isReuse](const auto &key,
std::vector<std::shared_ptr<SoftBusClient>> &connects) -> bool {
for (auto &connect : connects) {
if (connect->GetQoSType() != qosType) {
continue;
}
if (!isOHOSType && connect->needRemove) {
isReuse = true;
return false;
}
conn = connect;
return true;
connects_.Compute(deviceId.deviceId, [&pipeInfo, &deviceId, &conn, qosType, isOHOSType, &isReuse](const auto &key,
std::vector<std::shared_ptr<SoftBusClient>> &connects) -> bool {
for (auto &connect : connects) {
if (connect->GetQoSType() != qosType) {
continue;
}
if (!isOHOSType && connect->needRemove) {
isReuse = true;
return false;
}
auto connect = std::make_shared<SoftBusClient>(pipeInfo, deviceId, qosType);
connects.emplace_back(connect);
conn = connect;
return true;
});
}
auto connect = std::make_shared<SoftBusClient>(pipeInfo, deviceId, qosType);
connects.emplace_back(connect);
conn = connect;
return true;
});
if (!isOHOSType && isReuse) {
Reuse(pipeInfo, deviceId, qosType, conn);
}
@ -226,8 +225,11 @@ Status SoftBusAdapter::SendData(const PipeInfo &pipeInfo, const DeviceId &device
return Status::RATE_LIMIT;
}
if (status != Status::SUCCESS) {
auto task = [this, conn]() {
conn->OpenConnect(&clientListener_);
auto task = [this, connect = std::weak_ptr<SoftBusClient>(conn)]() {
auto conn = connect.lock();
if (conn != nullptr) {
conn->OpenConnect(&clientListener_);
}
};
auto networkId = DmAdapter::GetInstance().GetDeviceInfo(deviceId.deviceId).networkId;
ConnectManager::GetInstance()->ApplyConnect(networkId, task);

View File

@ -36,6 +36,7 @@ SoftBusClient::SoftBusClient(const PipeInfo& pipeInfo, const DeviceId& deviceId,
SoftBusClient::~SoftBusClient()
{
ZLOGI("Shutdown socket:%{public}d", socket_);
if (socket_ > 0) {
Shutdown(socket_);
}
@ -111,7 +112,8 @@ Status SoftBusClient::OpenConnect(const ISocketListener *listener)
ZLOGE("OpenSessionByAsync client is nullptr.");
return;
}
ZLOGI("Bind Start, socket:%{public}d type:%{public}u", clientSocket, type);
ZLOGI("Bind Start, device:%{public}s socket:%{public}d type:%{public}u",
KvStoreUtils::ToBeAnonymous(client->device_.deviceId).c_str(), clientSocket, type);
auto status = client->Open(clientSocket, QOS_INFOS[type % QOS_BUTT], listener);
if (status == Status::SUCCESS) {
Context::GetInstance().NotifySessionReady(client->device_.deviceId);

View File

@ -142,7 +142,7 @@ HWTEST_F(SessionManagerTest, PackAndUnPack01, TestSize.Level2)
ASSERT_NE(sendHandler, nullptr);
uint32_t routeHeadSize = 0;
sendHandler->GetHeadDataSize(routeHeadSize);
ASSERT_GT(routeHeadSize, 0);
ASSERT_EQ(routeHeadSize, 0);
std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(routeHeadSize);
sendHandler->FillHeadData(data.get(), routeHeadSize, routeHeadSize);
@ -152,7 +152,6 @@ HWTEST_F(SessionManagerTest, PackAndUnPack01, TestSize.Level2)
uint32_t parseSize = 1;
recvHandler->ParseHeadData(data.get(), routeHeadSize, parseSize, users);
EXPECT_EQ(routeHeadSize, parseSize);
ASSERT_EQ(users.size(), 1);
ASSERT_EQ(users[0], "100");
ASSERT_EQ(users.size(), 0);
}
} // namespace

View File

@ -568,6 +568,7 @@ HWTEST_F(KVDBGeneralStoreTest, Release, TestSize.Level0)
auto ret = store->Release();
EXPECT_EQ(ret, 0);
store = new (std::nothrow) KVDBGeneralStore(metaData_);
store->ref_ = 0;
ret = store->Release();
EXPECT_EQ(ret, 0);
store->ref_ = 2;