From 4377778a5771d013f5be28e896268ab627bff8a7 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 6 Dec 2024 15:38:44 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfoundation/distributedhar?= =?UTF-8?q?dware/device=5Fmanager=E6=A8=A1=E5=9D=97=E7=9A=84=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../relationshipsyncmgr/dm_transport_msg.cpp | 24 ++++++++++++++++--- .../relationship_sync_mgr.cpp | 17 +++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index 0fa4e6996..06eb92233 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -34,8 +34,14 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) if (foregroundUserIdArr == nullptr) { return; } + cJSON *numberObj = nullptr; for (auto const &userId : userIdsMsg.foregroundUserIds) { - cJSON_AddItemToArray(foregroundUserIdArr, cJSON_CreateNumber(userId)); + numberObj = cJSON_CreateNumber(userId); + if (numberObj != nullptr || !cJSON_AddItemToArray(foregroundUserIdArr, numberObj)) { + cJSON_Delete(numberObj); + cJSON_Delete(foregroundUserIdArr); + return; + } } cJSON_AddItemToObject(jsonObject, FOREGROUND_USERIDS_MSG_USERIDS_KEY, foregroundUserIdArr); @@ -43,8 +49,14 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) if (backgroundUserIdArr == nullptr) { return; } + cJSON *backgroundNumberObj = nullptr; for (auto const &userId : userIdsMsg.backgroundUserIds) { - cJSON_AddItemToArray(backgroundUserIdArr, cJSON_CreateNumber(userId)); + backgroundNumberObj = cJSON_CreateNumber(userId); + if (backgroundNumberObj == nullptr || !cJSON_AddItemToArray(backgroundUserIdArr, backgroundNumberObj)) { + cJSON_Delete(backgroundNumberObj); + cJSON_Delete(backgroundUserIdArr); + return; + } } cJSON_AddItemToObject(jsonObject, BACKGROUND_USERIDS_MSG_USERIDS_KEY, backgroundUserIdArr); } @@ -149,8 +161,14 @@ void ToJson(cJSON *jsonObject, const NotifyUserIds ¬ifyUserIds) if (userIdArr == nullptr) { return; } + cJSON *userIdNumberObj = nullptr; for (auto const &userId : notifyUserIds.userIds) { - cJSON_AddItemToArray(userIdArr, cJSON_CreateNumber(userId)); + userIdNumberObj = cJSON_CreateNumber(userId); + if (userIdNumberObj == nullptr || !cJSON_AddItemToArray(userIdArr, userIdNumberObj)) { + cJSON_Delete(userIdNumberObj); + cJSON_Delete(userIdArr); + return; + } } cJSON_AddItemToObject(jsonObject, DSOFTBUS_NOTIFY_USERIDS_USERIDKEY, userIdArr); } diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 9d2c88dcb..2a7ddb86f 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -469,8 +469,14 @@ cJSON *RelationShipChangeMsg::ToPayLoadJson() const } return nullptr; } + cJSON *numberObj = nullptr; for (uint32_t index = 0; index < len; index++) { - cJSON_AddItemToArray(arrayObj, cJSON_CreateNumber(payload[index])); + numberObj = cJSON_CreateNumber(payload[index]); + if (numberObj == nullptr || !cJSON_AddItemToArray(arrayObj, numberObj)) { + cJSON_Delete(numberObj); + cJSON_Delete(arrayObj); + return nullptr; + } } if (payload != nullptr) { delete[] payload; @@ -500,8 +506,15 @@ std::string RelationShipChangeMsg::ToJson() const cJSON_Delete(msg); return ""; } + cJSON *udidStringObj = nullptr; for (uint32_t index = 0; index < peerUdids.size(); index++) { - cJSON_AddItemToArray(udidArrayObj, cJSON_CreateString(peerUdids[index].c_str())); + udidStringObj = cJSON_CreateString(peerUdids[index].c_str()); + if (udidStringObj == nullptr || !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()); -- Gitee From 243f4770a7c266c572315d2ee8e0226fbb576339 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 6 Dec 2024 18:11:41 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfoundation/distributedhar?= =?UTF-8?q?dware/device=5Fmanager=E6=A8=A1=E5=9D=97=E7=9A=84=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- services/service/src/relationshipsyncmgr/dm_transport_msg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index 06eb92233..022c55ff1 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -37,7 +37,7 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) cJSON *numberObj = nullptr; for (auto const &userId : userIdsMsg.foregroundUserIds) { numberObj = cJSON_CreateNumber(userId); - if (numberObj != nullptr || !cJSON_AddItemToArray(foregroundUserIdArr, numberObj)) { + if (numberObj == nullptr || !cJSON_AddItemToArray(foregroundUserIdArr, numberObj)) { cJSON_Delete(numberObj); cJSON_Delete(foregroundUserIdArr); return; -- Gitee From fcc65b37e892850b0a98a9f37c24eb69d2a06725 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Tue, 10 Dec 2024 16:43:30 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfoundation/distributedhar?= =?UTF-8?q?dware/device=5Fmanager=E6=A8=A1=E5=9D=97=E7=9A=84=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- services/service/src/relationshipsyncmgr/dm_transport_msg.cpp | 3 --- .../service/src/relationshipsyncmgr/relationship_sync_mgr.cpp | 2 -- 2 files changed, 5 deletions(-) diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index 022c55ff1..c22f2a1c9 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -38,7 +38,6 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) for (auto const &userId : userIdsMsg.foregroundUserIds) { numberObj = cJSON_CreateNumber(userId); if (numberObj == nullptr || !cJSON_AddItemToArray(foregroundUserIdArr, numberObj)) { - cJSON_Delete(numberObj); cJSON_Delete(foregroundUserIdArr); return; } @@ -53,7 +52,6 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) for (auto const &userId : userIdsMsg.backgroundUserIds) { backgroundNumberObj = cJSON_CreateNumber(userId); if (backgroundNumberObj == nullptr || !cJSON_AddItemToArray(backgroundUserIdArr, backgroundNumberObj)) { - cJSON_Delete(backgroundNumberObj); cJSON_Delete(backgroundUserIdArr); return; } @@ -165,7 +163,6 @@ void ToJson(cJSON *jsonObject, const NotifyUserIds ¬ifyUserIds) for (auto const &userId : notifyUserIds.userIds) { userIdNumberObj = cJSON_CreateNumber(userId); if (userIdNumberObj == nullptr || !cJSON_AddItemToArray(userIdArr, userIdNumberObj)) { - cJSON_Delete(userIdNumberObj); cJSON_Delete(userIdArr); return; } diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 2a7ddb86f..edaa3cd68 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -473,7 +473,6 @@ cJSON *RelationShipChangeMsg::ToPayLoadJson() const for (uint32_t index = 0; index < len; index++) { numberObj = cJSON_CreateNumber(payload[index]); if (numberObj == nullptr || !cJSON_AddItemToArray(arrayObj, numberObj)) { - cJSON_Delete(numberObj); cJSON_Delete(arrayObj); return nullptr; } @@ -510,7 +509,6 @@ 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_AddItemToArray(udidArrayObj, udidStringObj)) { - cJSON_Delete(udidStringObj); cJSON_Delete(udidArrayObj); cJSON_Delete(msg); return ""; -- Gitee From 2c119ef4c395832fa3c081f46c04c8a06d9251a0 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Thu, 12 Dec 2024 10:27:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfoundation/distributedhar?= =?UTF-8?q?dware/device=5Fmanager=E6=A8=A1=E5=9D=97=E7=9A=84=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- services/service/src/relationshipsyncmgr/dm_transport_msg.cpp | 3 +++ .../service/src/relationshipsyncmgr/relationship_sync_mgr.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp index c22f2a1c9..022c55ff1 100644 --- a/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp +++ b/services/service/src/relationshipsyncmgr/dm_transport_msg.cpp @@ -38,6 +38,7 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) for (auto const &userId : userIdsMsg.foregroundUserIds) { numberObj = cJSON_CreateNumber(userId); if (numberObj == nullptr || !cJSON_AddItemToArray(foregroundUserIdArr, numberObj)) { + cJSON_Delete(numberObj); cJSON_Delete(foregroundUserIdArr); return; } @@ -52,6 +53,7 @@ void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg) for (auto const &userId : userIdsMsg.backgroundUserIds) { backgroundNumberObj = cJSON_CreateNumber(userId); if (backgroundNumberObj == nullptr || !cJSON_AddItemToArray(backgroundUserIdArr, backgroundNumberObj)) { + cJSON_Delete(backgroundNumberObj); cJSON_Delete(backgroundUserIdArr); return; } @@ -163,6 +165,7 @@ void ToJson(cJSON *jsonObject, const NotifyUserIds ¬ifyUserIds) for (auto const &userId : notifyUserIds.userIds) { userIdNumberObj = cJSON_CreateNumber(userId); if (userIdNumberObj == nullptr || !cJSON_AddItemToArray(userIdArr, userIdNumberObj)) { + cJSON_Delete(userIdNumberObj); cJSON_Delete(userIdArr); return; } diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index edaa3cd68..2a7ddb86f 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -473,6 +473,7 @@ cJSON *RelationShipChangeMsg::ToPayLoadJson() const for (uint32_t index = 0; index < len; index++) { numberObj = cJSON_CreateNumber(payload[index]); if (numberObj == nullptr || !cJSON_AddItemToArray(arrayObj, numberObj)) { + cJSON_Delete(numberObj); cJSON_Delete(arrayObj); return nullptr; } @@ -509,6 +510,7 @@ 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_AddItemToArray(udidArrayObj, udidStringObj)) { + cJSON_Delete(udidStringObj); cJSON_Delete(udidArrayObj); cJSON_Delete(msg); return ""; -- Gitee