From 2b5ac108a3064e7815c3ac91b9b363082f9ac35c Mon Sep 17 00:00:00 2001 From: "marcin.matula@cognizant.com" Date: Thu, 9 Jan 2025 17:02:19 +0100 Subject: [PATCH] RDKBWIFI-17 Fixes for lack of cJSON_free for cJSON_Print output --- src/cli/main.c | 4 +++- src/cmd/em_cmd.cpp | 1 + src/dm/dm_easy_mesh.cpp | 13 +++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cli/main.c b/src/cli/main.c index 44b9328..4925dc4 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -111,7 +111,9 @@ int main(int argc, const char *argv[]) if ((node = exec(line, strlen(line), NULL)) != NULL) { if ((obj = (cJSON *)network_tree_to_json(node)) != NULL) { - printf("%s\n", cJSON_Print(obj)); + char* tmp = cJSON_Print(obj); + printf("%s\n", tmp); + cJSON_free(tmp); cJSON_Delete(obj); } free_network_tree(node); diff --git a/src/cmd/em_cmd.cpp b/src/cmd/em_cmd.cpp index 1551762..9a2eec2 100644 --- a/src/cmd/em_cmd.cpp +++ b/src/cmd/em_cmd.cpp @@ -111,6 +111,7 @@ char *em_cmd_t::status_to_string(em_cmd_out_status_t status, em_status_string_t tmp = cJSON_Print(obj); strncpy(str, tmp, strlen(tmp) + 1); + cJSON_free(tmp); cJSON_Delete(obj); return str; diff --git a/src/dm/dm_easy_mesh.cpp b/src/dm/dm_easy_mesh.cpp index 1d1217d..f8b0b39 100644 --- a/src/dm/dm_easy_mesh.cpp +++ b/src/dm/dm_easy_mesh.cpp @@ -353,7 +353,10 @@ int dm_easy_mesh_t::encode_config_reset(em_subdoc_info_t *subdoc, const char *ke formatted_json = cJSON_Print(parent_obj); printf("%s:%d: %s\n", __func__, __LINE__, formatted_json); - snprintf(subdoc->buff,sizeof(em_subdoc_data_buff_t),"%s",cJSON_Print(parent_obj)); + cJSON_free(formatted_json); + char* tmp = cJSON_Print(parent_obj); + snprintf(subdoc->buff,sizeof(em_subdoc_data_buff_t),"%s",tmp); + cJSON_free(tmp); cJSON_Delete(parent_obj); return 0; } @@ -608,7 +611,10 @@ int dm_easy_mesh_t::encode_config_test(em_subdoc_info_t *subdoc, const char *key formatted_json = cJSON_Print(parent_obj); printf("%s:%d: %s\n", __func__, __LINE__, formatted_json); - snprintf(subdoc->buff,sizeof(em_subdoc_data_buff_t),"%s",cJSON_Print(parent_obj)); + cJSON_free(formatted_json); + char* tmp = cJSON_Print(parent_obj); + snprintf(subdoc->buff,sizeof(em_subdoc_data_buff_t),"%s",tmp); + cJSON_free(tmp); cJSON_Delete(parent_obj); return 0; } @@ -1888,6 +1894,7 @@ void dm_easy_mesh_t::create_autoconfig_renew_json_cmd(char* src_mac_addr, char* cJSON_AddItemToObject(root, "wfa-dataelements:Renew", renew); char* tmp = cJSON_Print(root); snprintf(autoconfig_renew_json, sizeof(autoconfig_renew_json), "%s", tmp); + cJSON_free(tmp); cJSON_Delete(root); } @@ -1909,6 +1916,7 @@ void dm_easy_mesh_t::create_ap_cap_query_json_cmd(char* src_mac_addr, char* agen cJSON_AddItemToObject(root, "wfa-dataelements:Radiocap", query_info); char* tmp = cJSON_Print(root); snprintf(ap_query_json, sizeof(ap_query_json), "%s", tmp); + cJSON_free(tmp); cJSON_Delete(root); } @@ -1931,6 +1939,7 @@ void dm_easy_mesh_t::create_client_cap_query_json_cmd(char* src_mac_addr, char* cJSON_AddItemToObject(root, "wfa-dataelements:Clientcap", query_info); char* tmp = cJSON_Print(root); snprintf(ap_query_json, sizeof(ap_query_json), "%s", tmp); + cJSON_free(tmp); cJSON_Delete(root); }