From 3e0b8e3e0284ec53ce2488a340ca078325b71c34 Mon Sep 17 00:00:00 2001 From: guoyi Date: Fri, 25 Jul 2025 21:34:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guoyi --- .../hichain/hichain_auth_connector.cpp | 8 ++- .../service/src/ipc/lite/ipc_server_stub.cpp | 3 +- .../src/relationshipsyncmgr/dm_comm_tool.cpp | 7 +- .../relationshipsyncmgr/dm_transport_msg.cpp | 17 +++-- .../relationship_sync_mgr.cpp | 10 ++- .../dm_auth_manager_fuzzer.cpp | 12 +++- .../hichain_connector_fuzzer.cpp | 37 +++++----- .../onrequest_fuzzer/on_request_fuzzer.cpp | 8 ++- .../UTTest_hichain_auth_connector.cpp | 18 ++++- .../UTTest_hichain_connector.cpp | 14 +++- .../auth_manager_fuzzer.cpp | 12 +++- .../unittest/UTTest_relationship_sync_mgr.cpp | 72 ++++++++++++++----- 12 files changed, 158 insertions(+), 60 deletions(-) diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index b1f2fd031..a9ee38a8d 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -382,10 +382,10 @@ int32_t HiChainAuthConnector::QueryCredentialInfo(int32_t userId, const JsonObje const CredManager *cm = GetCredMgrInstance(); char *credIdList = nullptr; - ret = cm->queryCredentialByParams(userId, queryParams.Dump().c_str(), - &credIdList); + ret = cm->queryCredentialByParams(userId, queryParams.Dump().c_str(), &credIdList); if (ret != DM_OK) { LOGE("HiChainAuthConnector::QueryCredentialInfo fail to query credential id list with ret %{public}d.", ret); + FreeJsonString(credIdList); return ERR_DM_FAILED; } JsonObject credIdListJson(credIdList); @@ -405,6 +405,7 @@ int32_t HiChainAuthConnector::QueryCredentialInfo(int32_t userId, const JsonObje ret = cm->queryCredInfoByCredId(userId, credId.c_str(), &returnCredInfo); if (ret != DM_OK) { LOGE("HiChainAuthConnector::QueryCredentialInfo fail to query credential info."); + FreeJsonString(returnCredInfo); return ERR_DM_FAILED; } JsonObject credInfoJson(returnCredInfo); @@ -427,6 +428,7 @@ int32_t HiChainAuthConnector::QueryCredInfoByCredId(int32_t userId, std::string int32_t ret = cm->queryCredInfoByCredId(userId, credId.c_str(), &returnCredInfo); if (ret != DM_OK) { LOGE("[HICHAIN]::QueryCredInfoByCredId failed, ret: %{public}d.", ret); + FreeJsonString(returnCredInfo); return ret; } JsonObject credInfoJson(returnCredInfo); diff --git a/services/service/src/ipc/lite/ipc_server_stub.cpp b/services/service/src/ipc/lite/ipc_server_stub.cpp index 3ceaa679f..1b7f6d8a7 100644 --- a/services/service/src/ipc/lite/ipc_server_stub.cpp +++ b/services/service/src/ipc/lite/ipc_server_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -103,6 +103,7 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) AddDeathRecipient(svc, DeathCb, pkgName, &cbId); svcId.cbId = cbId; std::string strPkgName = reinterpret_cast(name); + delete[] pkgName; return IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId); } diff --git a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp index 09b7dbb0b..088d4e61c 100644 --- a/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp +++ b/services/service/src/relationshipsyncmgr/dm_comm_tool.cpp @@ -676,7 +676,12 @@ int32_t DMCommTool::CreateUserStopMessage(int32_t stopUserId, std::string &msgSt cJSON_Delete(root); return ERR_DM_FAILED; } - cJSON_AddItemToObject(root, USER_STOP_MSG_KEY, numberObj); + if (!cJSON_AddItemToObject(root, USER_STOP_MSG_KEY, numberObj)) { + LOGE("add numberObj to root failed."); + cJSON_Delete(numberObj); + cJSON_Delete(root); + return ERR_DM_FAILED; + } char *msg = cJSON_PrintUnformatted(root); if (msg == nullptr) { cJSON_Delete(root); diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index 1344d1168..2a0abcdc1 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -53,7 +53,10 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) return; } } - cJSON_AddItemToObject(jsonObject, FOREGROUND_USERIDS_MSG_USERIDS_KEY, foregroundUserIdArr); + if (!cJSON_AddItemToObject(jsonObject, FOREGROUND_USERIDS_MSG_USERIDS_KEY, foregroundUserIdArr)) { + cJSON_Delete(foregroundUserIdArr); + return; + } cJSON *backgroundUserIdArr = cJSON_CreateArray(); if (backgroundUserIdArr == nullptr) { @@ -68,7 +71,10 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) return; } } - cJSON_AddItemToObject(jsonObject, BACKGROUND_USERIDS_MSG_USERIDS_KEY, backgroundUserIdArr); + if (!cJSON_AddItemToObject(jsonObject, BACKGROUND_USERIDS_MSG_USERIDS_KEY, backgroundUserIdArr)) { + cJSON_Delete(backgroundUserIdArr); + return; + } cJSON_AddBoolToObject(jsonObject, IS_NEW_EVENT_KEY, userIdsMsg.isNewEvent); } @@ -185,7 +191,10 @@ void ToJson(cJSON *jsonObject, const NotifyUserIds ¬ifyUserIds) return; } } - cJSON_AddItemToObject(jsonObject, DSOFTBUS_NOTIFY_USERIDS_USERIDKEY, userIdArr); + if (!cJSON_AddItemToObject(jsonObject, DSOFTBUS_NOTIFY_USERIDS_USERIDKEY, userIdArr)) { + cJSON_Delete(userIdArr); + return; + } } void FromJson(const cJSON *jsonObject, NotifyUserIds ¬ifyUserIds) diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 8d9923d2d..bec3b0930 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -802,16 +802,17 @@ std::string RelationShipChangeMsg::ToJson() const } cJSON_AddNumberToObject(msg, MSG_TYPE, (uint32_t)type); cJSON *arrayObj = ToPayLoadJson(); - if (arrayObj == nullptr) { + if (arrayObj == nullptr || !cJSON_AddItemToObject(msg, MSG_VALUE, arrayObj)) { LOGE("ArrayObj is nullptr."); + cJSON_Delete(arrayObj); cJSON_Delete(msg); return ""; } - cJSON_AddItemToObject(msg, MSG_VALUE, arrayObj); cJSON *udidArrayObj = cJSON_CreateArray(); - if (udidArrayObj == nullptr) { + if (udidArrayObj == nullptr || !cJSON_AddItemToObject(msg, MSG_PEER_UDID, udidArrayObj)) { LOGE("cJSON_CreateArray failed"); + cJSON_Delete(udidArrayObj); cJSON_Delete(msg); return ""; } @@ -819,18 +820,15 @@ std::string RelationShipChangeMsg::ToJson() const for (uint32_t index = 0; index < peerUdids.size(); index++) { udidStringObj = cJSON_CreateString(peerUdids[index].c_str()); if (udidStringObj == nullptr) { - cJSON_Delete(udidArrayObj); cJSON_Delete(msg); return ""; } if (!cJSON_AddItemToArray(udidArrayObj, udidStringObj)) { cJSON_Delete(udidStringObj); - cJSON_Delete(udidArrayObj); cJSON_Delete(msg); return ""; } } - cJSON_AddItemToObject(msg, MSG_PEER_UDID, udidArrayObj); cJSON_AddStringToObject(msg, MSG_ACCOUNTID, accountName.c_str()); char *retStr = cJSON_PrintUnformatted(msg); if (retStr == nullptr) { diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.cpp b/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.cpp index 55d9ba976..950fa6a1d 100644 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.cpp +++ b/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.cpp @@ -78,7 +78,11 @@ void DmAuthSrcManagerFuzzTest(const uint8_t* data, size_t size) authManager->DeleteGroup(str, str); authManager->AuthDeviceTransmit(g_requestId, data, size); authManager->AuthDeviceSessionKey(g_requestId, data, size); - authManager->AuthDeviceRequest(g_requestId, g_operationCode, str.c_str()); + char *ret = authManager->AuthDeviceRequest(g_requestId, g_operationCode, str.c_str()); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } authManager->OnDataReceived(g_sessionId, str); authManager->OnAuthDeviceDataReceived(g_sessionId, str); } @@ -111,7 +115,11 @@ void DmAuthSinkManagerFuzzTest(const uint8_t* data, size_t size) authManager->DeleteGroup(str, str); authManager->AuthDeviceTransmit(g_requestId, data, size); authManager->AuthDeviceSessionKey(g_requestId, data, size); - authManager->AuthDeviceRequest(g_requestId, g_operationCode, str.c_str()); + char *ret = authManager->AuthDeviceRequest(g_requestId, g_operationCode, str.c_str()); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } authManager->OnDataReceived(g_sessionId, str); authManager->OnAuthDeviceDataReceived(g_sessionId, str); } diff --git a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp index 856d739cf..1fc177894 100644 --- a/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp +++ b/test/commonfuzztest/hichainconnector_fuzzer/hichain_connector_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -178,17 +178,14 @@ void HiChainConnectorThirdFuzzTest(const uint8_t* data, size_t size) std::vector groupList; std::string queryParams(reinterpret_cast(data), size); std::string pkgName(reinterpret_cast(data), size); - std::string groupId(reinterpret_cast(data), size); std::string deviceId(reinterpret_cast(data), size); std::string reqDeviceId(reinterpret_cast(data), size); JsonObject jsonOutObj; std::shared_ptr callback; std::string jsonStr(reinterpret_cast(data), size); int32_t groupType = fdp.ConsumeIntegral(); - int32_t switchUserId = fdp.ConsumeIntegral(); std::string reqParams(reinterpret_cast(data), size); std::string credentialInfo(reinterpret_cast(data), size); - int operationCode = GroupOperationCode::MEMBER_JOIN; hichainConnector->deviceGroupManager_ = nullptr; hichainConnector->AddMember(deviceId, queryParams); hichainConnector->getRegisterInfo(queryParams, jsonStr); @@ -198,7 +195,11 @@ void HiChainConnectorThirdFuzzTest(const uint8_t* data, size_t size) hichainConnector->GetGroupInfoCommon(authType, queryParams, pkgName.c_str(), groupList); hichainConnector->hiChainConnectorCallback_ = nullptr; hichainConnector->GetConnectPara(deviceId, reqDeviceId); - hichainConnector->onRequest(requestId, operationCode, reqParams.c_str()); + char *ret = hichainConnector->onRequest(requestId, GroupOperationCode::MEMBER_JOIN, reqParams.c_str()); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } hichainConnector->RegisterHiChainCallback(std::make_shared()); if (hichainConnector->deviceGroupManager_ == nullptr) { hichainConnector->deviceGroupManager_ = GetGmInstance(); @@ -228,7 +229,6 @@ void HiChainConnectorForthFuzzTest(const uint8_t* data, size_t size) std::string returnData(reinterpret_cast(data), size); std::string userId = "userId_forth"; int32_t authType = fdp.ConsumeIntegral(); - int operationCode = GroupOperationCode::MEMBER_JOIN; int errCode = 102; std::vector syncGroupList; std::vector> delACLInfoVec; @@ -246,18 +246,19 @@ void HiChainConnectorForthFuzzTest(const uint8_t* data, size_t size) hichainConnector->DealRedundanceGroup(userId, authType); hichainConnector->DeleteGroupByACL(delACLInfoVec, userIdVec); hichainConnector->IsNeedDelete(groupName, authType, delACLInfoVec); - hichainConnector->onFinish(requestId, operationCode, returnData.c_str()); - hichainConnector->onError(requestId, operationCode, errCode, returnData.c_str()); - hichainConnector->onRequest(requestId, operationCode, returnData.c_str()); - operationCode = GroupOperationCode::GROUP_CREATE; - hichainConnector->onFinish(requestId, operationCode, returnData.c_str()); - hichainConnector->onError(requestId, operationCode, errCode, returnData.c_str()); - operationCode == GroupOperationCode::MEMBER_DELETE; - hichainConnector->onFinish(requestId, operationCode, returnData.c_str()); - hichainConnector->onError(requestId, operationCode, errCode, returnData.c_str()); - operationCode == GroupOperationCode::GROUP_DISBAND; - hichainConnector->onFinish(requestId, operationCode, returnData.c_str()); - hichainConnector->onError(requestId, operationCode, errCode, returnData.c_str()); + hichainConnector->onFinish(requestId, GroupOperationCode::MEMBER_JOIN, returnData.c_str()); + hichainConnector->onError(requestId, GroupOperationCode::MEMBER_JOIN, errCode, returnData.c_str()); + char *ret = hichainConnector->onRequest(requestId, GroupOperationCode::MEMBER_JOIN, returnData.c_str()); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } + hichainConnector->onFinish(requestId, GroupOperationCode::GROUP_CREATE, returnData.c_str()); + hichainConnector->onError(requestId, GroupOperationCode::GROUP_CREATE, errCode, returnData.c_str()); + hichainConnector->onFinish(requestId, GroupOperationCode::MEMBER_DELETE, returnData.c_str()); + hichainConnector->onError(requestId, GroupOperationCode::MEMBER_DELETE, errCode, returnData.c_str()); + hichainConnector->onFinish(requestId, GroupOperationCode::GROUP_DISBAND, returnData.c_str()); + hichainConnector->onError(requestId, GroupOperationCode::GROUP_DISBAND, errCode, returnData.c_str()); hichainConnector->GenRequestId(); hichainConnector->GetRelatedGroups(deviceId, groupList); hichainConnector->GetRelatedGroupsExt(deviceId, groupList); diff --git a/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp b/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp index baaeb16e3..4a9a99f96 100644 --- a/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp +++ b/test/commonfuzztest/onrequest_fuzzer/on_request_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -66,7 +66,11 @@ void OnRequestFuzzTest(const uint8_t* data, size_t size) std::shared_ptr hichainConnector = std::make_shared(); hichainConnector->RegisterHiChainCallback(std::make_shared()); - hichainConnector->onRequest(requestId, operationCode, reqParams); + char *ret = hichainConnector->onRequest(requestId, operationCode, reqParams); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } } } } diff --git a/test/commonunittest/UTTest_hichain_auth_connector.cpp b/test/commonunittest/UTTest_hichain_auth_connector.cpp index 447e195b5..fd929baa5 100644 --- a/test/commonunittest/UTTest_hichain_auth_connector.cpp +++ b/test/commonunittest/UTTest_hichain_auth_connector.cpp @@ -130,8 +130,12 @@ HWTEST_F(HiChainAuthConnectorTest, onRequest_001, testing::ext::TestSize.Level1) int operationCode = 0; char *reqParams = nullptr; hiChain_->dmDeviceAuthCallback_ = nullptr; - hiChain_->onRequest(requestId, operationCode, reqParams); + char *ret = hiChain_->onRequest(requestId, operationCode, reqParams); EXPECT_EQ(hiChain_->dmDeviceAuthCallback_, nullptr); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } } HWTEST_F(HiChainAuthConnectorTest, onRequest_002, testing::ext::TestSize.Level1) @@ -140,8 +144,12 @@ HWTEST_F(HiChainAuthConnectorTest, onRequest_002, testing::ext::TestSize.Level1) int operationCode = 0; char *reqParams = nullptr; hiChain_->dmDeviceAuthCallback_ = std::make_shared(); - hiChain_->onRequest(requestId, operationCode, reqParams); + char *ret = hiChain_->onRequest(requestId, operationCode, reqParams); EXPECT_NE(hiChain_->dmDeviceAuthCallback_, nullptr); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } } HWTEST_F(HiChainAuthConnectorTest, onRequest_003, testing::ext::TestSize.Level1) @@ -152,8 +160,12 @@ HWTEST_F(HiChainAuthConnectorTest, onRequest_003, testing::ext::TestSize.Level1) char *reqParams = nullptr; hiChain_->dmDeviceAuthCallback_ = std::make_shared(); hiChain_->dmDeviceAuthCallback_->AuthDeviceError(requestId, errorCode); - hiChain_->onRequest(requestId, operationCode, reqParams); + char *ret = hiChain_->onRequest(requestId, operationCode, reqParams); EXPECT_NE(hiChain_->dmDeviceAuthCallback_, nullptr); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } } HWTEST_F(HiChainAuthConnectorTest, onFinish_001, testing::ext::TestSize.Level1) diff --git a/test/commonunittest/UTTest_hichain_connector.cpp b/test/commonunittest/UTTest_hichain_connector.cpp index 81ea90399..878a528c4 100755 --- a/test/commonunittest/UTTest_hichain_connector.cpp +++ b/test/commonunittest/UTTest_hichain_connector.cpp @@ -419,12 +419,22 @@ HWTEST_F(HichainConnectorTest, onRequest_003, testing::ext::TestSize.Level1) EXPECT_CALL(*mockCallback, GetPinCode(testing::_)) .Times(1) .WillOnce(testing::Return(ERR_DM_FAILED)); - EXPECT_NE(hiChainConnector->onRequest(requestId, operationCode, reqParams), nullptr); + char *ret1 = hiChainConnector->onRequest(requestId, operationCode, reqParams); + EXPECT_NE(ret1, nullptr); + if (ret1 != nullptr) { + free(ret1); + ret1 = nullptr; + } EXPECT_CALL(*mockCallback, GetPinCode(testing::_)) .Times(1) .WillOnce(testing::Return(DM_OK)); - EXPECT_NE(hiChainConnector->onRequest(requestId, operationCode, reqParams), nullptr); + char *ret2 = hiChainConnector->onRequest(requestId, operationCode, reqParams); + EXPECT_NE(ret2, nullptr); + if (ret2 != nullptr) { + free(ret2); + ret2 = nullptr; + } } /** diff --git a/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp index 7adab1c32..0e8e6668b 100644 --- a/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp +++ b/test/servicesfuzztest/authmanager_fuzzer/auth_manager_fuzzer.cpp @@ -126,7 +126,11 @@ void AuthDeviceRequestFuzzTest(FuzzedDataProvider &fdp) int64_t requestId = fdp.ConsumeIntegral(); int operationCode = fdp.ConsumeIntegral(); const char* reqParams = fdp.ConsumeRandomLengthString().c_str(); - authManager->AuthDeviceRequest(requestId, operationCode, reqParams); + char *ret = authManager->AuthDeviceRequest(requestId, operationCode, reqParams); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } } void SetAuthTypeFuzzTest(FuzzedDataProvider &fdp) @@ -362,7 +366,11 @@ void AuthSinkDeviceRequestFuzzTest(FuzzedDataProvider &fdp) int64_t requestId = fdp.ConsumeIntegral(); int operationCode = fdp.ConsumeIntegral(); const char* reqParams = fdp.ConsumeRandomLengthString().c_str(); - authSinkManager->AuthDeviceRequest(requestId, operationCode, reqParams); + char *ret = authSinkManager->AuthDeviceRequest(requestId, operationCode, reqParams); + if (ret != nullptr) { + free(ret); + ret = nullptr; + } authManager->DeleteTimer(); authManager->GetBindCallerInfo(); } diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index a92269252..04ba66200 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -254,6 +254,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToSyncFrontOrBackUserIdPayLoad_001, testing:: uint32_t len = 0; bool result = msg.ToSyncFrontOrBackUserIdPayLoad(msgPtr, len); ASSERT_EQ(result, false); + if (msgPtr != nullptr) { + delete[] msgPtr; + msgPtr = nullptr; + } } HWTEST_F(ReleationShipSyncMgrTest, ToSyncFrontOrBackUserIdPayLoad_002, testing::ext::TestSize.Level1) @@ -266,6 +270,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToSyncFrontOrBackUserIdPayLoad_002, testing:: msg.syncUserIdFlag = true; bool result = msg.ToSyncFrontOrBackUserIdPayLoad(msgPtr, len); ASSERT_EQ(result, true); + if (msgPtr != nullptr) { + delete[] msgPtr; + msgPtr = nullptr; + } } HWTEST_F(ReleationShipSyncMgrTest, FromAccountLogoutPayLoad_001, testing::ext::TestSize.Level1) @@ -1003,8 +1011,8 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_001, testing::ext::TestSiz ASSERT_TRUE(result); ASSERT_NE(msgPtr, nullptr); ASSERT_GT(len, 0); - delete[] msgPtr; + msgPtr = nullptr; msg.userId = 0; msg.accountId = "test_01"; @@ -1013,6 +1021,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_001, testing::ext::TestSiz result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(len, 9); EXPECT_EQ(result, true); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } /** @@ -1033,8 +1045,8 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_002, testing::ext::TestSiz ASSERT_TRUE(result); ASSERT_NE(msgPtr, nullptr); ASSERT_GT(len, 0); - delete[] msgPtr; + msgPtr = nullptr; msg.userId = 1; msg.accountId = "test"; @@ -1042,6 +1054,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_002, testing::ext::TestSiz len = 0; result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } /** @@ -1062,8 +1078,8 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_003, testing::ext::TestSiz ASSERT_TRUE(result); ASSERT_NE(msgPtr, nullptr); ASSERT_GT(len, 0); - delete[] msgPtr; + msgPtr = nullptr; } HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_004, testing::ext::TestSize.Level1) @@ -1080,8 +1096,8 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_004, testing::ext::TestSiz ASSERT_TRUE(result); ASSERT_NE(msgPtr, nullptr); ASSERT_GT(len, 0); - delete[] msgPtr; + msgPtr = nullptr; } HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_005, testing::ext::TestSize.Level1) @@ -1106,6 +1122,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_005, testing::ext::TestSiz len = 0; result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, false); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } /** @@ -1122,6 +1142,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_006, testing::ext::TestSiz uint32_t len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } /** @@ -1142,6 +1166,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_007, testing::ext::TestSiz uint32_t len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } /** @@ -1153,16 +1181,16 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_008, testing::ext::TestSiz RelationShipChangeMsg msg; msg.type = RelationShipChangeType::DEL_USER; msg.userId = 12345; - + uint8_t* msgPtr = nullptr; uint32_t len = 0; - + bool result = msg.ToBroadcastPayLoad(msgPtr, len); ASSERT_TRUE(result); ASSERT_NE(msgPtr, nullptr); ASSERT_GT(len, 0); - delete[] msgPtr; + msgPtr = nullptr; msg.userId = 7; msg.accountId = "test"; @@ -1170,6 +1198,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_008, testing::ext::TestSiz len = 0; result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, true); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } /** @@ -1181,16 +1213,16 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_009, testing::ext::TestSiz RelationShipChangeMsg msg; msg.type = RelationShipChangeType::STOP_USER; msg.userId = 12345; - + uint8_t* msgPtr = nullptr; uint32_t len = 0; - + bool result = msg.ToBroadcastPayLoad(msgPtr, len); ASSERT_TRUE(result); ASSERT_NE(msgPtr, nullptr); ASSERT_GT(len, 0); - delete[] msgPtr; + msgPtr = nullptr; } HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_010, testing::ext::TestSize.Level1) @@ -1199,15 +1231,15 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_010, testing::ext::TestSiz msg.type = RelationShipChangeType::SHARE_UNBIND; msg.userId = 12345; msg.peerUdids = {"udid1", "udid2"}; - + uint8_t* msgPtr = nullptr; uint32_t len = 0; - + bool result = msg.ToBroadcastPayLoad(msgPtr, len); ASSERT_TRUE(result); ASSERT_EQ(msgPtr, nullptr); - delete[] msgPtr; + msgPtr = nullptr; } HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_011, testing::ext::TestSize.Level1) @@ -1229,6 +1261,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_011, testing::ext::TestSiz len = 0; result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, false); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } /** @@ -1245,6 +1281,10 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_012, testing::ext::TestSiz uint32_t len = 0; bool result = msg.ToBroadcastPayLoad(load, len); EXPECT_EQ(result, false); + if (load != nullptr) { + delete[] load; + load = nullptr; + } } HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_013, testing::ext::TestSize.Level1) @@ -1254,14 +1294,14 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_013, testing::ext::TestSiz msg.userId = 12345; msg.tokenId = 67890; msg.peerUdids = {"udid1", "udid2"}; - + uint8_t* msgPtr = nullptr; uint32_t len = 0; - + bool result = msg.ToBroadcastPayLoad(msgPtr, len); ASSERT_TRUE(result); - delete[] msgPtr; + msgPtr = nullptr; } HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_001, testing::ext::TestSize.Level1) -- Gitee