From ffa1fefe8d8baf25cab5c5dcd4300460e6a0e4cb Mon Sep 17 00:00:00 2001 From: "injun.yang" Date: Fri, 6 Jul 2018 17:03:21 +0900 Subject: [PATCH] Code cleanup Change-Id: Id446db2902cdefbae4a8aa3401053744f493495e Signed-off-by: injun.yang --- bt-api/bt-common.c | 32 +++++++++++++++++--------------- bt-service/bt-request-handler.c | 5 ----- bt-service/bt-service-audio.c | 28 ---------------------------- bt-service/bt-service-event-sender.c | 2 -- bt-service/bt-service-gap-agent.c | 2 -- bt-service/bt-service-hid.c | 6 ------ test/gatt-test/bluetooth-gatt-test.c | 5 ----- 7 files changed, 17 insertions(+), 63 deletions(-) diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index 792ca88..0f664f6 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -83,6 +83,7 @@ GDBusConnection *g_bus_get_private_conn(void) NULL, /* GDBusAuthObserver */ NULL, &error); + g_free(address); if (!private_gconn) { if (error) { BT_ERR("Unable to connect to dbus: %s", error->message); @@ -1509,13 +1510,13 @@ int _bt_discover_service_uuids(char *address, char *remote_uuid) proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL, BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL, &err); - g_free(object_path); - - retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - if (err) { - BT_ERR("DBus Error: [%s]", err->message); - g_clear_error(&err); + if (proxy == NULL) { + if (err) { + BT_ERR("DBus Error: [%s]", err->message); + g_clear_error(&err); + } + return BLUETOOTH_ERROR_INTERNAL; } ret = g_dbus_proxy_call_sync(proxy, "Get", g_variant_new("(ss)", BT_DEVICE_INTERFACE, "UUIDs"), @@ -1569,24 +1570,24 @@ int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class) GVariant *value = NULL; GVariant *result = NULL; unsigned int class = 0x00; - int ret = BLUETOOTH_ERROR_INTERNAL; + int ret = BLUETOOTH_ERROR_NONE; gconn = __get_gdbus_connection(); retv_if(gconn == NULL, BLUETOOTH_ERROR_INTERNAL); - object_path = _bt_get_device_object_path(address); + object_path = _bt_get_device_object_path(address); retv_if(object_path == NULL, BLUETOOTH_ERROR_INTERNAL); proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL, BT_BLUEZ_NAME, object_path, BT_PROPERTIES_INTERFACE, NULL, &err); - - g_free(object_path); - - retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - if (err) { - BT_ERR("DBus Error: [%s]", err->message); - g_clear_error(&err); + if (proxy == NULL) { + ret = BLUETOOTH_ERROR_INTERNAL; + if (err) { + BT_ERR("DBus Error: [%s]", err->message); + g_clear_error(&err); + } + goto done; } result = g_dbus_proxy_call_sync(proxy, "Get", @@ -1606,6 +1607,7 @@ int _bt_get_cod_by_address(char *address, bluetooth_device_class_t *dev_class) } done: + g_free(object_path); if (proxy) g_object_unref(proxy); diff --git a/bt-service/bt-request-handler.c b/bt-service/bt-request-handler.c index ca63020..e8c8266 100644 --- a/bt-service/bt-request-handler.c +++ b/bt-service/bt-request-handler.c @@ -70,7 +70,6 @@ static const gchar bt_service_introspection_xml[] = " " ""; -GDBusNodeInfo *node_info = NULL; static gboolean name_acquired = FALSE; static char *current_sender_playing = NULL; @@ -3090,10 +3089,6 @@ void _bt_service_unregister(void) g_object_unref(bt_service_conn); bt_service_conn = NULL; } - if (node_info) { - g_dbus_node_info_unref(node_info); - node_info = NULL; - } if (owner_id > 0) { g_bus_unown_name(owner_id); owner_id = 0; diff --git a/bt-service/bt-service-audio.c b/bt-service/bt-service-audio.c index 3b32b20..e9a53bb 100644 --- a/bt-service/bt-service-audio.c +++ b/bt-service/bt-service-audio.c @@ -513,11 +513,6 @@ void _bt_add_headset_to_list(int type, int status, const char *address) } connected_device = g_malloc0(sizeof(bt_connected_headset_data_t)); - /* Fix : NULL_RETURNS */ - if (connected_device == NULL) { - BT_ERR("No memory allocated"); - return; - } connected_device->device_state = status; if ((status == BT_STATE_CONNECTED) || (status == BT_STATE_CONNECTING)) @@ -697,11 +692,6 @@ int _bt_audio_connect(int request_id, int type, _bt_convert_addr_type_to_string(address, device_address->addr); func_data = g_malloc0(sizeof(bt_audio_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; - goto fail; - } func_data->address = g_strdup(address); func_data->req_id = request_id; @@ -842,12 +832,6 @@ int _bt_audio_disconnect(int request_id, int type, _bt_convert_addr_type_to_string(address, device_address->addr); func_data = g_malloc0(sizeof(bt_audio_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - BT_ERR("Memory allocation error"); - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; - goto fail; - } func_data->address = g_strdup(address); func_data->req_id = request_id; func_data->pending = BT_PENDING_NONE; @@ -988,12 +972,6 @@ int _bt_hf_connect(int request_id, } func_data = g_malloc0(sizeof(bt_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; - goto fail; - } - func_data->address = g_strdup(address); func_data->req_id = request_id; uuid = g_strdup(HFP_AG_UUID); @@ -1053,12 +1031,6 @@ int _bt_hf_disconnect(int request_id, } func_data = g_malloc0(sizeof(bt_function_data_t)); - /* Fix : NULL_RETURNS */ - if (func_data == NULL) { - result = BLUETOOTH_ERROR_MEMORY_ALLOCATION; - goto fail; - } - func_data->address = g_strdup(address); func_data->req_id = request_id; uuid = g_strdup(HFP_AG_UUID); diff --git a/bt-service/bt-service-event-sender.c b/bt-service/bt-service-event-sender.c index 0fda180..bcdc9ca 100644 --- a/bt-service/bt-service-event-sender.c +++ b/bt-service/bt-service-event-sender.c @@ -552,7 +552,6 @@ int _bt_init_service_event_sender(void) } conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); if (conn == NULL) { BT_ERR("conn == NULL"); if (err) { @@ -587,7 +586,6 @@ int _bt_init_hf_local_term_event_sender(void) } conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL); if (conn == NULL) { BT_ERR("conn == NULL"); if (err) { diff --git a/bt-service/bt-service-gap-agent.c b/bt-service/bt-service-gap-agent.c index 150a1f0..a747ad5 100644 --- a/bt-service/bt-service-gap-agent.c +++ b/bt-service/bt-service-gap-agent.c @@ -112,8 +112,6 @@ gboolean _gap_agent_register_osp_server(GapAgentPrivate *agent, return FALSE; server = g_malloc0(sizeof(bt_agent_osp_server_t)); - retv_if(server == NULL, FALSE); - server->type = type; if (type == BT_RFCOMM_SERVER) { server->uuid = g_strdup(uuid); diff --git a/bt-service/bt-service-hid.c b/bt-service/bt-service-hid.c index f319faf..28e47f7 100644 --- a/bt-service/bt-service-hid.c +++ b/bt-service/bt-service-hid.c @@ -179,9 +179,6 @@ int _bt_hid_connect(int request_id, _bt_convert_addr_type_to_string(address, device_address->addr); func_data = g_malloc0(sizeof(bt_function_data_t)); - /* Fix : NULL_RETURNS */ - retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION); - func_data->address = g_strdup(address); func_data->req_id = request_id; uuid = HID_UUID; @@ -218,9 +215,6 @@ int _bt_hid_disconnect(int request_id, _bt_convert_addr_type_to_string(address, device_address->addr); func_data = g_malloc0(sizeof(bt_function_data_t)); - /* Fix : NULL_RETURNS */ - retv_if(func_data == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION); - func_data->address = g_strdup(address); func_data->req_id = request_id; diff --git a/test/gatt-test/bluetooth-gatt-test.c b/test/gatt-test/bluetooth-gatt-test.c index c029075..d2738fc 100755 --- a/test/gatt-test/bluetooth-gatt-test.c +++ b/test/gatt-test/bluetooth-gatt-test.c @@ -110,11 +110,6 @@ char * get_bd_from_file(char *filename) } buf = g_malloc0(20); - /* Fix : NULL_RETURNS */ - if (buf == NULL) { - close(fd); - return NULL; - } if (read(fd, buf, 17) < 17) { perror("Can't load firmware"); -- 2.7.4