From 2447b25c218cd96bf905ec8bed8c051cfd3d52ad Mon Sep 17 00:00:00 2001 From: luming Date: Mon, 19 Aug 2024 11:42:40 +0800 Subject: [PATCH 1/3] [Bug] Using `cJSON_free` to free memory allocated by `cJSON_Print` issueNo: https://gitee.com/openharmony/developtools_syscap_codec/issues/IAKW57 Signed-off-by: luming --- interfaces/inner_api/syscap_interface.h | 4 ++-- src/create_pcid.c | 4 +++- tools/syscap_collector.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.h b/interfaces/inner_api/syscap_interface.h index a26bfae..f0c4bd5 100644 --- a/interfaces/inner_api/syscap_interface.h +++ b/interfaces/inner_api/syscap_interface.h @@ -26,7 +26,7 @@ #define PCID_MAIN_BYTES 128 #define PCID_MAIN_INTS 32 -#define E_EORROR (-1) +#define E_ERROR (-1) #define E_OK 0 #define E_APIVERSION 1 #define E_SYSCAP 2 @@ -54,7 +54,7 @@ char *DecodeRpcidToStringFormat(const char *inputFile); * rpcidString, input string format rpcid. * result, output comparison results. * retval: - * E_EORROR, compare failed. + * E_ERROR, compare failed. * E_OK, compare successful and meet the requirements. * E_APIVERSION, compare successful but api version too low. * E_SYSCAP, compare successful but missing some syscaps. diff --git a/src/create_pcid.c b/src/create_pcid.c index d7000b8..f9d6af3 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -759,7 +759,9 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) ret = 0; FAILED: - SafeFree(jsonBuffer); + if (jsonBuffer != NULL) { + cJSON_free(jsonBuffer) + } SafeFree(priSyscapStr); cJSON_Delete(sysCapObj); cJSON_Delete(rootObj); diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index 18ee661..74c0f96 100755 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -208,7 +208,7 @@ def _check_path_prefix(paths): def traversal_files(subsystem_path, _files): for item in os.scandir(subsystem_path): - if is_symlik(item.path): + if is_symlink(item.path): continue elif item.is_file() and item.name == 'ohos.build': _files.append(item.path) @@ -230,7 +230,7 @@ def get_file_type(file_path): return 'unknown' -def is_symlik(file_path): +def is_symlink(file_path): file_type = get_file_type(file_path) if file_type == 'symlink': link_target = os.readlink(file_path) -- Gitee From 49c75b54389722bb5d4a1c76b3d616cf93df0d5f Mon Sep 17 00:00:00 2001 From: Luming Date: Mon, 19 Aug 2024 15:07:07 +0000 Subject: [PATCH 2/3] update src/create_pcid.c. Signed-off-by: Luming --- src/create_pcid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index f9d6af3..5db820a 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -760,7 +760,7 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) FAILED: if (jsonBuffer != NULL) { - cJSON_free(jsonBuffer) + cJSON_free(jsonBuffer); } SafeFree(priSyscapStr); cJSON_Delete(sysCapObj); -- Gitee From 70470274b99e2157c8cd68e40e7075382d995657 Mon Sep 17 00:00:00 2001 From: Luming Date: Tue, 20 Aug 2024 01:51:54 +0000 Subject: [PATCH 3/3] update src/create_pcid.c. Signed-off-by: Luming --- src/create_pcid.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index 5db820a..7b99567 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -759,9 +759,7 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) ret = 0; FAILED: - if (jsonBuffer != NULL) { - cJSON_free(jsonBuffer); - } + cJSON_free(jsonBuffer); SafeFree(priSyscapStr); cJSON_Delete(sysCapObj); cJSON_Delete(rootObj); -- Gitee