From fc07271d7a62cf432e9e0f235de7dbb2f7c6b2ed Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 1 Apr 2014 14:04:57 +0200 Subject: [PATCH] android/gatt: Refator bt_gatt_register function This fix possible memory leaks and not unregistering IPC handlers if function failed. --- android/gatt.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/android/gatt.c b/android/gatt.c index 75a80a558..941582a7c 100644 --- a/android/gatt.c +++ b/android/gatt.c @@ -2095,31 +2095,32 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr) { DBG(""); - bacpy(&adapter_addr, addr); + conn_list = queue_new(); + conn_wait_queue = queue_new(); + gatt_clients = queue_new(); - hal_ipc = ipc; + if (!conn_list || !conn_wait_queue || !gatt_clients) { + error("gatt: Failed to allocate memory for queues"); - conn_list = queue_new(); - if (!conn_list) { - error("gatt: Can not create conn queue"); - return false; - } + queue_destroy(gatt_clients, NULL); + gatt_clients = NULL; + + queue_destroy(conn_list, NULL); + conn_list = NULL; + + queue_destroy(conn_wait_queue, NULL); + conn_wait_queue = NULL; - conn_wait_queue = queue_new(); - if (!conn_wait_queue) { - error("gatt: Can not create conn queue"); return false; } + bacpy(&adapter_addr, addr); + + hal_ipc = ipc; + ipc_register(hal_ipc, HAL_SERVICE_ID_GATT, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); - gatt_clients = queue_new(); - if (!gatt_clients) { - error("gatt: Cannot allocate gatt_clients"); - return false; - } - return true; } -- 2.47.3