From 321b1208ee4696a8921e2d1b3626866cbd50dfe0 Mon Sep 17 00:00:00 2001 From: lichao Date: Sun, 21 Apr 2024 20:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- interfaces/inner_api/syscap_interface.c | 8 +++++--- src/create_pcid.c | 3 +++ src/syscap_tool.c | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index a4a342e..887d498 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -245,6 +245,7 @@ bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *o *bufferPos = '\0'; if (sprintf_s(*outputArray, SINGLE_SYSCAP_LEN, "SystemCapability.%s", buffer) == -1) { free(outputArray); + free(output); return false; } bufferPos = buffer; @@ -328,24 +329,25 @@ FREE_SYSCAP_OUT: static int32_t TransStringFormatAndSaveSyscap(struct FreeAfterDecodeRpcidInfo freeAfterDecodeRpcidInfo, cJSON *sysCapArray, const char *inputFile) { + int32_t ret = -1; // trans to string format sysCapArray = cJSON_GetObjectItem(freeAfterDecodeRpcidInfo.rpcidRoot, "syscap"); if (sysCapArray == NULL || !cJSON_IsArray(sysCapArray)) { PRINT_ERR("Get syscap failed. Input file: %s\n", inputFile); - return -1; + return ret; } freeAfterDecodeRpcidInfo.sysCapArraySize = cJSON_GetArraySize(sysCapArray); if (freeAfterDecodeRpcidInfo.sysCapArraySize < 0) { PRINT_ERR("Get syscap size failed. Input file: %s\n", inputFile); - return -1; + return ret; } // malloc for save os syscap index freeAfterDecodeRpcidInfo.osSysCapIndex = (uint16_t *)malloc(sizeof(uint16_t) * freeAfterDecodeRpcidInfo.sysCapArraySize); if (freeAfterDecodeRpcidInfo.osSysCapIndex == NULL) { PRINT_ERR("malloc failed.\n"); - return -1; } + free(freeAfterDecodeRpcidInfo.osSysCapIndex); return 0; } diff --git a/src/create_pcid.c b/src/create_pcid.c index 1a606df..da181d8 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -286,10 +286,12 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) ret += SetPriSyscap(pcidBuffer, jsonPriSyscapObj, privateCapSize, allPriSyscapStrLen); ret += SetPCIDHeader(pcidBuffer, jsonRootObj); if (ret != 0) { + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, FREE_CREATE_PCID_BUFFER_OUT, ret); } ret = CheckConvertedContextSaveAsFile(outDirPath, pcidBuffer, pcidLength, ret); + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, FREE_CREATE_PCID_BUFFER_OUT, ret); } @@ -520,6 +522,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, outputFileName); } + free(strJson); return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_CONVERT_OUT, ret); } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index ff4e084..b79c6b7 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -266,6 +266,7 @@ int32_t RPCIDDecode(char *inputFile, char *outputPath) FREE_RPCID_ROOT: cJSON_Delete(rpcidRoot); + free(convertedBuffer); FREE_CONTEXT_OUT: FreeContextBuffer(contextBuffer); return ret;