From cd9e35acccf53453cf686a5b82e7ceac7707bea9 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Thu, 17 Sep 2020 08:05:45 +0900 Subject: [PATCH] Fix the coverity issues Change-Id: I1998c8489a074fbaab3d4e9e1aa567db3b3f4f3e Signed-off-by: DoHyun Pyun --- bt-api/bt-event-handler.c | 13 +++++++++++-- bt-oal/bluez_hal/src/bt-hal-gatt-server.c | 4 ++++ bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c | 16 ++++++++++++---- bt-service/services/mesh/bt-service-mesh-cdb.c | 1 + bt-service/services/mesh/bt-service-mesh-config-client.c | 15 ++++++++------- bt-service/services/mesh/bt-service-mesh-model.c | 2 +- bt-service/services/mesh/bt-service-mesh-network.c | 16 +++++++++++++--- bt-service/services/mesh/bt-service-mesh-util.c | 1 + 8 files changed, 51 insertions(+), 17 deletions(-) diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index 09691d8..bef35df 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -4366,8 +4366,17 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data) const char *path; const char *interface = BT_EVENT_SERVICE; - if (is_initialized == FALSE) - _bt_init_event_handler(); + if (is_initialized == FALSE) { + int ret; + + ret = _bt_init_event_handler(); + + if (ret != BLUETOOTH_ERROR_NONE && + ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) { + BT_ERR("Fail to init the event handler"); + return ret; + } + } if (__bt_event_is_registered(event_type) == TRUE) { BT_ERR("The event is already registed"); diff --git a/bt-oal/bluez_hal/src/bt-hal-gatt-server.c b/bt-oal/bluez_hal/src/bt-hal-gatt-server.c index 3b267f1..26d15c8 100644 --- a/bt-oal/bluez_hal/src/bt-hal-gatt-server.c +++ b/bt-oal/bluez_hal/src/bt-hal-gatt-server.c @@ -2327,6 +2327,8 @@ static int __bt_hal_gatt_init(void) owner_id = g_bus_own_name_on_connection(g_conn, name, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL); + + g_free(name); } INFO("Owner ID [%d]", owner_id); @@ -3376,6 +3378,8 @@ static bt_status_t gatt_server_update_att_value(int server_if, int attribute_han } g_free(serv_path); + g_strfreev(line_argv); + line_argv = g_strsplit_set(char_path, "/", 0); serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]); diff --git a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c index e9714b5..a4b6e77 100644 --- a/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-mesh-dbus-handler.c @@ -410,9 +410,10 @@ static gint __compare_proxy_path(gconstpointer data, gconstpointer user_data) char **strings = g_strsplit(path, "node", 2); ret = g_strcmp0(strings[1], app_uuid_path); - g_free(strings[0]); - g_free(strings[1]); + + g_strfreev(strings); l_free(app_uuid_path); + return ret; } @@ -1197,12 +1198,13 @@ static struct l_dbus_message *__mesh_node_add_failed( INFO("Mesh: Provisioning failed:\n"); str = l_util_hexstring_upper(uuid, 16); INFO("Mesh: UUID = [%s] Reason [%s]", str, reason); - l_free(str); ev.status = BT_STATUS_FAIL; ev.reason = __bt_mesh_util_get_prov_error_code(str); memcpy(ev.dev_uuid, uuid, 16); + l_free(str); + if (mesh_event_cb) mesh_event_cb(HAL_EV_MESH_PROVISIONING_FINISHED, (void*)&ev, sizeof(ev)); @@ -1986,10 +1988,14 @@ static void __bt_hal_mesh_add_node_reply( static void __bt_hal_mesh_add_node_setup(struct l_dbus_message *msg, void *user_data) { - char *uuid; + char *uuid = NULL; bt_uuid_t *dev = user_data; struct l_dbus_message_builder *builder; + uuid = l_util_hexstring(dev->uu, 16); + if (uuid == NULL) + return; + INFO("Mesh: Add Node Setup UUID [%s]", uuid); builder = l_dbus_message_builder_new(msg); @@ -1998,6 +2004,8 @@ static void __bt_hal_mesh_add_node_setup(struct l_dbus_message *msg, l_dbus_message_builder_leave_array(builder); l_dbus_message_builder_finalize(builder); l_dbus_message_builder_destroy(builder); + + g_free(uuid); } bt_status_t _bt_hal_mesh_provision_device( diff --git a/bt-service/services/mesh/bt-service-mesh-cdb.c b/bt-service/services/mesh/bt-service-mesh-cdb.c index 583c80c..6771eda 100644 --- a/bt-service/services/mesh/bt-service-mesh-cdb.c +++ b/bt-service/services/mesh/bt-service-mesh-cdb.c @@ -2100,6 +2100,7 @@ _bt_mesh_cdb_t* _bt_mesh_conf_load(const char *file_name, sz = read(fd, str, st.st_size); if (sz != st.st_size) { BT_ERR("Mesh: Failed to read configuration file [%s]", file_name); + close(fd); g_free(str); return NULL; } diff --git a/bt-service/services/mesh/bt-service-mesh-config-client.c b/bt-service/services/mesh/bt-service-mesh-config-client.c index 5a7810b..9b57173 100644 --- a/bt-service/services/mesh/bt-service-mesh-config-client.c +++ b/bt-service/services/mesh/bt-service-mesh-config-client.c @@ -1156,13 +1156,13 @@ void _bt_mesh_config_client_devkey_msg_handler( int n; struct mesh_pending_request *req; - if (_bt_mesh_util_opcode_get(data, data_len, &opcode, &n)) { - BT_INFO("Mesh: Opcode of response data [0x%2.2x], actual data len [%d]", opcode, n); - data_len -= n; - data += n; - } else + if (_bt_mesh_util_opcode_get(data, data_len, &opcode, &n) == false) return; + BT_INFO("Mesh: Opcode of response data [0x%2.2x], actual data len [%d]", opcode, n); + data_len -= n; + data += n; + BT_INFO("Mesh: Received %s (len %u) opcode [0x%2.2x]", __mesh_get_opcode_string(opcode), data_len, opcode); @@ -1171,10 +1171,11 @@ void _bt_mesh_config_client_devkey_msg_handler( if (req) { BT_INFO("Mesh: Got Config Request"); cmd = req->cmd; - __mesh_request_remove(req); l_queue_remove(pending_requests, req); - } else + __mesh_request_remove(req); + } else { cmd = NULL; + } switch (opcode & ~MESH_OPCODE_UNRELIABLE) { diff --git a/bt-service/services/mesh/bt-service-mesh-model.c b/bt-service/services/mesh/bt-service-mesh-model.c index 65bea08..1e4ce05 100644 --- a/bt-service/services/mesh/bt-service-mesh-model.c +++ b/bt-service/services/mesh/bt-service-mesh-model.c @@ -418,8 +418,8 @@ void _bt_mesh_msg_handler(event_mesh_message_t *event) if (req) { BT_INFO("Mesh: Got Request"); - __mesh_request_remove(req); l_queue_remove(pending_msg_requests, req); + __mesh_request_remove(req); } bluetooth_mesh_model_msg_t param; diff --git a/bt-service/services/mesh/bt-service-mesh-network.c b/bt-service/services/mesh/bt-service-mesh-network.c index 800a26a..ba5c7c7 100644 --- a/bt-service/services/mesh/bt-service-mesh-network.c +++ b/bt-service/services/mesh/bt-service-mesh-network.c @@ -277,7 +277,7 @@ int _bt_mesh_network_remove_net_configuration( bluetooth_mesh_network_t *net) { GSList *l; - char *file_path; + char *file_path = NULL; _bt_mesh_cdb_t *cdb_cfg = NULL; uint8_t net_uuid[16]; BT_INFO("Mesh: Remove network Configuration"); @@ -302,12 +302,16 @@ int _bt_mesh_network_remove_net_configuration( BT_INFO("Mesh: CDB Backup File path[%s]", file_path); /* Remove the config */ - if (!_bt_mesh_util_delete_file(cdb_cfg->cfg_fname)) + if (!_bt_mesh_util_delete_file(cdb_cfg->cfg_fname)) { + g_free(file_path); return BLUETOOTH_ERROR_INTERNAL; + } /* Remove the config backup */ - if (!_bt_mesh_util_delete_file(file_path)) + if (!_bt_mesh_util_delete_file(file_path)) { + g_free(file_path); return BLUETOOTH_ERROR_INTERNAL; + } BT_INFO("Mesh: Config DB file removed!!"); cdb_list = g_slist_remove(cdb_list, cdb_cfg); @@ -1564,9 +1568,15 @@ int _bt_mesh_network_load(const char *app_cred, BT_INFO("Mesh: File Absolute Path [%s]", file_path); cdb_cfg = _bt_mesh_conf_load(file_path, token); + + g_free(file_path); + file_path = NULL; + if (cdb_cfg) break; } + + g_dir_close(dir); } g_free(file_path); diff --git a/bt-service/services/mesh/bt-service-mesh-util.c b/bt-service/services/mesh/bt-service-mesh-util.c index ccb13e0..2d44d0b 100644 --- a/bt-service/services/mesh/bt-service-mesh-util.c +++ b/bt-service/services/mesh/bt-service-mesh-util.c @@ -277,6 +277,7 @@ bool _bt_mesh_util_delete_file(const char *filename) if (fstat(fd, &st) < 0) { BT_ERR("Mesh: Failed to stat [%s]", filename); + close(fd); return false; } -- 2.7.4