From fc9e8077e716e916b6c543778d0d2a5b8313f5cf Mon Sep 17 00:00:00 2001 From: fuzikun Date: Wed, 23 Mar 2022 17:52:53 +0800 Subject: [PATCH] bug fix: memory leak Signed-off-by: fuzikun --- common_lib/impl/src/string_util.c | 5 +++-- .../standard_client_unbind_exchange_task.c | 2 +- .../group_operation/peer_to_peer_group/peer_to_peer_group.c | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common_lib/impl/src/string_util.c b/common_lib/impl/src/string_util.c index b08e51b..45c0a39 100644 --- a/common_lib/impl/src/string_util.c +++ b/common_lib/impl/src/string_util.c @@ -241,11 +241,12 @@ int32_t ToUpperCase(const char *oriStr, char **desStr) if (oriStr == NULL || desStr == NULL) { return CLIB_ERR_NULL_PTR; } - *desStr = ClibMalloc(strlen(oriStr) + 1, 0); + uint32_t len = strlen(oriStr); + *desStr = ClibMalloc(len + 1, 0); if (*desStr == NULL) { return CLIB_ERR_BAD_ALLOC; } - for (uint32_t i = 0; i < strlen(oriStr); i++) { + for (uint32_t i = 0; i < len; i++) { if ((oriStr[i] >= 'a') && (oriStr[i] <= 'f')) { (*desStr)[i] = oriStr[i] - ASCII_CASE_DIFFERENCE_VALUE; } else { diff --git a/services/authenticators/src/account_unrelated/pake_task/standard_exchange_task/standard_client_unbind_exchange_task.c b/services/authenticators/src/account_unrelated/pake_task/standard_exchange_task/standard_client_unbind_exchange_task.c index c6014f9..f709474 100644 --- a/services/authenticators/src/account_unrelated/pake_task/standard_exchange_task/standard_client_unbind_exchange_task.c +++ b/services/authenticators/src/account_unrelated/pake_task/standard_exchange_task/standard_client_unbind_exchange_task.c @@ -61,7 +61,7 @@ static int ExchangeRequest(AsyBaseCurTask *task, PakeParams *params, const CJson res = ClientRequestStandardUnbindExchange(params, &(realTask->params)); if (res != HC_SUCCESS) { LOGE("ClientRequestStandardUnbindExchange failed"); - return res; + goto ERR; } // package message diff --git a/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c b/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c index faf5686..4f5a0a8 100644 --- a/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c +++ b/services/group_manager/src/group_operation/peer_to_peer_group/peer_to_peer_group.c @@ -286,6 +286,7 @@ static int32_t AddAuthIdAndUserTypeToParams(int32_t osAccountId, const char *gro int32_t res = HcGetUdid((uint8_t *)localUdid, INPUT_UDID_LEN); if (res != HC_SUCCESS) { LOGE("Failed to get local udid! res: %d", res); + DestroyDeviceEntry(deviceInfo); return HC_ERR_DB; }