From f94cf467b9f0ad81f3fc38910e7c9605907909da Mon Sep 17 00:00:00 2001 From: navyasher Date: Mon, 20 Jul 2026 11:38:59 +0530 Subject: [PATCH] RDKB-65777: Fixing coverity issue Reason for change: Fixing coverity issues. Test Procedure: Build should be successful and the regression test should also succeed Risks: Low Priority: P1 Signed-off-by: Navya_Sheregar@comcast.com --- .../platform/common/data_model/wifi_dml_api.c | 6 +++-- .../linux/he_bus/src/he_bus_connection.c | 7 +++++- .../platform/linux/he_bus/src/he_bus_core.c | 22 ++++++++++--------- .../linux/he_bus/src/he_bus_data_conversion.c | 1 + source/platform/rdkb/bus.c | 4 ++++ 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/source/platform/common/data_model/wifi_dml_api.c b/source/platform/common/data_model/wifi_dml_api.c index f35bf8fdf..a44d82707 100644 --- a/source/platform/common/data_model/wifi_dml_api.c +++ b/source/platform/common/data_model/wifi_dml_api.c @@ -1989,6 +1989,7 @@ static int update_json_param_legacy(char *p_key, char *partner_id, char *p_value if (data != NULL) { memset(data, 0, (sizeof(char) * (len + 1))); if (1 != fread(data, len, 1, file_read)) { + free(data); fclose(file_read); return RETURN_ERR; } @@ -2005,10 +2006,10 @@ static int update_json_param_legacy(char *p_key, char *partner_id, char *p_value return RETURN_ERR; } else if (strlen(data) != 0) { json = cJSON_Parse(data); + free(data); if (!json) { wifi_util_error_print(WIFI_DMCLI, "%s : json file parser error : [%d]\n", __func__, __LINE__); - free(data); return RETURN_ERR; } else { partner_obj = cJSON_GetObjectItem(json, partner_id); @@ -2084,6 +2085,7 @@ int update_json_param(char *p_key, char *partner_id, char *p_value, char *p_sour if (data != NULL) { memset(data, 0, (sizeof(char) * (len + 1))); if (1 != fread(data, len, 1, file_read)) { + free(data); fclose(file_read); return RETURN_ERR; } @@ -2101,10 +2103,10 @@ int update_json_param(char *p_key, char *partner_id, char *p_value, char *p_sour return RETURN_ERR; } else if (strlen(data) != 0) { json = cJSON_Parse(data); + free(data); if (!json) { wifi_util_error_print(WIFI_DMCLI, "%s : json file parser error : [%d]\n", __func__, __LINE__); - free(data); return RETURN_ERR; } else { partner_obj = cJSON_GetObjectItem(json, partner_id); diff --git a/source/platform/linux/he_bus/src/he_bus_connection.c b/source/platform/linux/he_bus/src/he_bus_connection.c index 196cd75d3..d1c6c3df5 100644 --- a/source/platform/linux/he_bus/src/he_bus_connection.c +++ b/source/platform/linux/he_bus/src/he_bus_connection.c @@ -627,6 +627,9 @@ void *ipc_unix_broadcast_client_start(void *arg) if (FD_ISSET(p_client_info->conn_info.fd, &read_fds)) { ret = recv_server_data(handle, &p_client_info->conn_info); if (ret == HE_BUS_ERROR_STREAM_CLOSED) { + if (p_client_info->conn_info.fd != SOCKET_INVALID_FD) { + close(p_client_info->conn_info.fd); + } p_client_info->conn_info.fd = -1; sleep(20); //@TODO TBD Do we need to trigger retry for server connection ? if (bus_client_bind(SOCKET_BROADCAST_SERVER_NAME, &p_client_info->conn_info) != @@ -640,7 +643,9 @@ void *ipc_unix_broadcast_client_start(void *arg) } } } - close(p_client_info->conn_info.fd); + if (p_client_info->conn_info.fd != SOCKET_INVALID_FD) { + close(p_client_info->conn_info.fd); + } return NULL; } diff --git a/source/platform/linux/he_bus/src/he_bus_core.c b/source/platform/linux/he_bus/src/he_bus_core.c index 09f23b1b5..098a83e3a 100644 --- a/source/platform/linux/he_bus/src/he_bus_core.c +++ b/source/platform/linux/he_bus/src/he_bus_core.c @@ -438,7 +438,7 @@ element_node_t *bus_insert_element(he_bus_handle_t handle, element_node_t *root, Its presumed a provider will register more elements under this, such as Device.WiFi.AccessPoint.{i}.Foo etc,... */ - if (elem->type == he_bus_element_type_table) { + if (elem->type == he_bus_element_type_table && current_node->child == NULL) { // trigger add table registration callback element_node_t *rowTemplate = get_empty_element_node(); rowTemplate->parent = current_node; @@ -903,7 +903,8 @@ he_bus_error_t he_bus_event_sub_to_provider(he_bus_handle_t handle, char *event_name; he_bus_raw_data_msg_t sub_data = { 0 }; - he_bus_raw_data_t payload_data; + he_bus_raw_data_t payload_data = { 0 }; + he_bus_stretch_buff_t raw_buff = { 0 }; int ret; sub_payload_data_t sub_input_data; @@ -921,8 +922,8 @@ he_bus_error_t he_bus_event_sub_to_provider(he_bus_handle_t handle, if (p_sub_data != NULL) { he_bus_core_error_print("%s:%d event:%s already subscribe with provider\r\n", __func__, __LINE__, event_name); - return he_bus_error_subscription_already_exist; // @TODO TBD Do we need to return error - // or not ? + status = he_bus_error_subscription_already_exist; + goto cleanup; // @TODO TBD Do we need to return error or not ? } else { sub_input_data.action = sub_data_map[index].action; sub_input_data.interval = sub_data_map[index].interval; @@ -937,18 +938,17 @@ he_bus_error_t he_bus_event_sub_to_provider(he_bus_handle_t handle, if (status != he_bus_error_success) { he_bus_core_error_print("%s:%d rem bus payload preapre is failed:%d for %s\r\n", __func__, __LINE__, status, event_name); - return status; + he_bus_free(payload_data.raw_data.bytes); + goto cleanup; } } } - he_bus_stretch_buff_t raw_buff = { 0 }; - if (convert_bus_raw_msg_data_to_buffer(&sub_data, &raw_buff) != he_bus_error_success) { he_bus_core_error_print("%s:%d wrong data for :%s namespace\r\n", __func__, __LINE__, sub_data.component_name); - FREE_BUFF_MEMORY(raw_buff.buff); - return he_bus_error_invalid_input; + status = he_bus_error_invalid_input; + goto cleanup; } he_bus_core_info_print("%s:%d event:%s subscribe event sub type:%d\r\n", __func__, __LINE__, @@ -992,7 +992,8 @@ he_bus_error_t he_bus_event_sub_to_provider(he_bus_handle_t handle, if (ret != HE_BUS_RETURN_OK) { he_bus_core_info_print("%s:%d event:%s subscribe send failure:%d\r\n", __func__, __LINE__, event_name, ret); - return he_bus_error_destination_not_reachable; + status = he_bus_error_destination_not_reachable; + goto cleanup; } else { for (uint32_t index = 0; index < num_of_sub; index++) { save_bus_sub_event_entries(handle, handle->sub_map, &sub_data_map[index]); @@ -1000,6 +1001,7 @@ he_bus_error_t he_bus_event_sub_to_provider(he_bus_handle_t handle, } } +cleanup: FREE_BUFF_MEMORY(raw_buff.buff); free_bus_msg_obj_data(&sub_data.data_obj); return status; diff --git a/source/platform/linux/he_bus/src/he_bus_data_conversion.c b/source/platform/linux/he_bus/src/he_bus_data_conversion.c index 57b326f3a..8624ab82a 100644 --- a/source/platform/linux/he_bus/src/he_bus_data_conversion.c +++ b/source/platform/linux/he_bus/src/he_bus_data_conversion.c @@ -600,6 +600,7 @@ he_bus_error_t process_bus_sub_event(he_bus_handle_t handle, int socket_fd, char p_obj_data->data.raw_data_len); p_sub_data->action = sub_recv_data.action; } else { + he_bus_free(p_sub_data); ELM_UNLOCK(node->element_mutex); he_bus_core_error_print("%s:%d wrong sub action raw data type:%d for %s\r\n", __func__, __LINE__, p_obj_data->data.data_type, p_obj_data->name); diff --git a/source/platform/rdkb/bus.c b/source/platform/rdkb/bus.c index 9e7f587c0..576286a8b 100644 --- a/source/platform/rdkb/bus.c +++ b/source/platform/rdkb/bus.c @@ -1388,6 +1388,7 @@ static bus_error_t bus_data_get(bus_handle_t *handle, char const *name, raw_data if (data->raw_data.bytes == NULL) { wifi_util_error_print(WIFI_BUS, "%s:%d: bus: memory alloc is failed:%d for name:%s\n", __func__, __LINE__, len, name); + rbusValue_Release(value); return bus_error_out_of_resources; } memcpy(data->raw_data.bytes, ptr, len); @@ -1677,11 +1678,13 @@ bus_error_t bus_method_invoke(bus_handle_t *handle, void *paramName, char *event prop = rbusObject_GetProperties(outParams); if (prop == NULL) { wifi_util_error_print(WIFI_BUS, "%s %d prop is NULL\n", __func__, __LINE__); + rbusObject_Release(outParams); return bus_error_general; } value = rbusProperty_GetValue(prop); if (value == NULL) { wifi_util_error_print(WIFI_BUS, "%s %d value is NULL\n", __func__, __LINE__); + rbusObject_Release(outParams); return bus_error_general; } switch (output_data->data_type) { @@ -1722,6 +1725,7 @@ bus_error_t bus_method_invoke(bus_handle_t *handle, void *paramName, char *event if (output_data->raw_data.bytes == NULL) { wifi_util_error_print(WIFI_BUS, "%s:%d: bus: memory alloc is failed:%d for name:%s\n", __func__, __LINE__, len, event); + rbusObject_Release(outParams); return bus_error_out_of_resources; } memcpy(output_data->raw_data.bytes, ptr, len);