Fix the memory leak 42/235342/1
authorinjun.yang <injun.yang@samsung.com>
Tue, 2 Jun 2020 04:56:47 +0000 (13:56 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 4 Jun 2020 04:17:13 +0000 (13:17 +0900)
[Model] All
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] memory leak on gatt connection
[Cause & Measure] release memory
[Checking Method]

[Team] Convergence BT
[Developer] Injun Yang
[Solution company] Samsung
[Change Type] Specification change

Change-Id: Id1268133170c202d2342f076d8302140c2e5ef0e
Signed-off-by: injun.yang <injun.yang@samsung.com>
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/bluez_hal/src/bt-hal-gatt-client.c
bt-oal/bluez_hal/src/bt-hal-gatt-server.c

index d388c98..a6ff12f 100644 (file)
@@ -1736,8 +1736,8 @@ static void __bt_hal_device_properties_lookup(GVariant *result, char *address)
                                        strlen(name) + 1, name);
                        ev->num_props++;
                        DBG("Device Name [%s] Property num [%d]", name, ev->num_props);
-                       g_variant_get(tmp_value, "s", &name);
                }
+               g_free(name);
 
                /* Class */
                tmp_value = g_variant_lookup_value(value, "Class", G_VARIANT_TYPE_UINT32);
@@ -1885,7 +1885,6 @@ static void __bt_hal_device_properties_lookup(GVariant *result, char *address)
                ev->num_props++;
                DBG("Device address [%s] property Num [%d]", address, ev->num_props);
 
-               g_free(name);
                g_variant_unref(value);
        } else {
                ERR("result  is NULL\n");
index 7c5d837..6c7835f 100644 (file)
@@ -934,6 +934,7 @@ static bt_status_t _gattc_client_search_service(int conn_id)
                                                while (g_variant_iter_loop(char_iter, "&o", &char_handle)) {
                                                        g_ptr_array_add(gp_char_array, (gpointer)char_handle);
                                                }
+                                               g_variant_iter_free(char_iter);
                                        }
                                }
                        }
index 0df6ebd..b46082c 100644 (file)
@@ -1390,129 +1390,135 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                event_cb(HAL_EV_GATT_INDICATE_CFM, (void *)&ev, sizeof(ev));
        } else if (g_strcmp0(method_name, "AcquireWrite") == 0) {
 
-                               uint16_t mtu = 512;
-                               int char_hdl = -1;
-                               struct hal_ev_gatt_server_acquire_write_res  ev;
-                               struct gatt_service_info *svc_info = NULL;
-                               struct gatt_req_info *req_info = NULL;
-                               struct gatt_client_info_t *conn_info = NULL;
-                               char * dev_path = NULL;
-                               char * link = 0;
-                               char  addr[BT_HAL_ADDRESS_STRING_SIZE];
-
-                               DBG("AcquireWrite : Application path %s, sender %s", object_path, sender);
-
-                               GVariantIter* iter;
-                               g_variant_get(parameters, "(a{sv})", &iter);
-                               char* key = NULL;
-                               GVariant* value = NULL;
-                               while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
-                                               if (g_strcmp0(key, "MTU") == 0)
-                                                       g_variant_get(value, "i", &mtu);
-                                               else if (g_strcmp0(key, "link") == 0)
-                                                       g_variant_get(value, "s", &link);
-                                               else if (g_strcmp0(key, "device") == 0)
-                                                       g_variant_get(value, "o", &dev_path);
-                               }
+               uint16_t mtu = 512;
+               int char_hdl = -1;
+               struct hal_ev_gatt_server_acquire_write_res  ev;
+               struct gatt_service_info *svc_info = NULL;
+               struct gatt_req_info *req_info = NULL;
+               struct gatt_client_info_t *conn_info = NULL;
+               char *dev_path = NULL;
+               char *link = NULL;
+               char  addr[BT_HAL_ADDRESS_STRING_SIZE];
+
+               DBG("AcquireWrite : Application path %s, sender %s", object_path, sender);
+
+               GVariantIter* iter;
+               g_variant_get(parameters, "(a{sv})", &iter);
+               char *key = NULL;
+               GVariant *value = NULL;
+               while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+                               if (g_strcmp0(key, "MTU") == 0)
+                                       g_variant_get(value, "i", &mtu);
+                               else if (g_strcmp0(key, "link") == 0)
+                                       g_variant_get(value, "s", &link);
+                               else if (g_strcmp0(key, "device") == 0)
+                                       g_variant_get(value, "o", &dev_path);
+               }
 
-                               DBG(" path  %s LINK = %s, MTU = %u", addr, link, mtu);
+               DBG(" path  %s LINK = %s, MTU = %u", addr, link, mtu);
 
-                               svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
+               svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
 
-                               _bt_hal_convert_device_path_to_address(dev_path, addr);
+               _bt_hal_convert_device_path_to_address(dev_path, addr);
 
-                               DBG("remote address %s", addr);
+               DBG("remote address %s", addr);
+               g_free(link);
+               g_free(dev_path);
 
-                               /* Check if device is already in connected list */
-                               conn_info = __bt_find_remote_gatt_client_info(addr);
+               /* Check if device is already in connected list */
+               conn_info = __bt_find_remote_gatt_client_info(addr);
+               if (conn_info == NULL) {
+                       ERR("Cleint info not found\n");
+                       g_variant_iter_free(iter);
+                       goto done;
+               }
 
-                               if (conn_info == NULL) {
-                                       ERR("Cleint info not found\n");
-                                       goto done;
-                               }
+               if (svc_info == NULL) {
+                       ERR("svc_info  info not found\n");
+                       g_variant_iter_free(iter);
+                       goto done;
+               }
 
-                               if (svc_info == NULL) {
-                                       ERR("svc_info  info not found\n");
-                                       goto done;
-                               }
+               /* Store requets information */
+               req_info = g_new0(struct gatt_req_info, 1);
+               req_info->attr_path = g_strdup(object_path);
+               req_info->svc_path = g_strdup(svc_info->serv_path);
+               req_info->request_id = conn_info->connection_id;
+               req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
+               req_info->offset = mtu;
+               req_info->context = invocation;
 
-                               /* Store requets information */
-                               req_info = g_new0(struct gatt_req_info, 1);
-                               req_info->attr_path = g_strdup(object_path);
-                               req_info->svc_path = g_strdup(svc_info->serv_path);
-                               req_info->request_id = conn_info->connection_id;
-                               req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
-                               req_info->offset = mtu;
-                               req_info->context = invocation;
+               /* Append request info in list of requests for the particular connection */
+               conn_info->gatt_req_info_list = g_slist_append(conn_info->gatt_req_info_list, req_info);
 
-                               /* Append request info in list of requests for the particular connection */
-                               conn_info->gatt_req_info_list = g_slist_append(conn_info->gatt_req_info_list, req_info);
+               /* Send HAL event */
+               memset(&ev, 0, sizeof(ev));
+               ev.conn_id = conn_info->connection_id;
+               ev.char_handl = char_hdl;
+               ev.mtu = mtu;
+               ev.trans_id = conn_info->connection_id;
+               _bt_hal_convert_addr_string_to_type(ev.bdaddr, addr);
+               event_cb(HAL_EV_GATT_SERVER_ACQUIRE_WRITE_RES, (void *)&ev, sizeof(ev));
+               g_variant_iter_free(iter);
+               return;
+       } else if (g_strcmp0(method_name, "AcquireNotify") == 0) {
 
-                               /* Send HAL event */
-                               memset(&ev, 0, sizeof(ev));
-                               ev.conn_id = conn_info->connection_id;
-                               ev.char_handl = char_hdl;
-                               ev.mtu = mtu;
-                               ev.trans_id = conn_info->connection_id;
-                               _bt_hal_convert_addr_string_to_type(ev.bdaddr, addr);
-                               event_cb(HAL_EV_GATT_SERVER_ACQUIRE_WRITE_RES, (void *)&ev, sizeof(ev));
-                       return;
-               } else if (g_strcmp0(method_name, "AcquireNotify") == 0) {
-
-                               uint16_t mtu = 512;
-                               int char_hdl = -1;
-                               struct hal_ev_gatt_server_acquire_notify  ev;
-                               struct gatt_service_info *svc_info = NULL;
-                               struct gatt_client_info_t *conn_info = NULL;
-                               struct gatt_req_info *req_info = NULL;
-
-                               DBG("AcquireNotify : Application path %s, sender %s", object_path, sender);
-
-                               GVariantIter* iter;
-                               g_variant_get(parameters, "(a{sv})", &iter);
-                               char* key = NULL;
-                               GVariant* value = NULL;
-                               while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
-                                               if (g_strcmp0(key, "MTU") == 0)
-                                                       g_variant_get(value, "q", &mtu);
-                               }
+               uint16_t mtu = 512;
+               int char_hdl = -1;
+               struct hal_ev_gatt_server_acquire_notify  ev;
+               struct gatt_service_info *svc_info = NULL;
+               struct gatt_client_info_t *conn_info = NULL;
+               struct gatt_req_info *req_info = NULL;
+
+               DBG("AcquireNotify : Application path %s, sender %s", object_path, sender);
 
-                               DBG("MTU = %u",  mtu);
+               GVariantIter* iter;
+               g_variant_get(parameters, "(a{sv})", &iter);
+               char* key = NULL;
+               GVariant* value = NULL;
+               while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+                               if (g_strcmp0(key, "MTU") == 0)
+                                       g_variant_get(value, "q", &mtu);
+               }
 
-                               svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
+               DBG("MTU = %u",  mtu);
 
-                       if (svc_info == NULL) {
-                                       ERR("svc_info  info not found\n");
-                                       goto done;
-                               }
+               svc_info = __bt_gatt_find_gatt_service_from_char(object_path, &char_hdl);
 
-                               /* Store requets information */
-                               req_info = g_new0(struct gatt_req_info, 1);
-                               req_info->attr_path = g_strdup(object_path);
-                               req_info->svc_path = g_strdup(svc_info->serv_path);
-                               req_info->request_id = 33;
-                               req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY;
-                               req_info->offset = mtu;
-                               req_info->context = invocation;
-
-                               conn_info = g_new0(struct gatt_client_info_t, 1);
-                               conn_info->addr = g_strdup(object_path);
-                               INFO("AcquireNotify : Added GATT client path[%s]", conn_info->addr);
-                               conn_info->connection_id = 33;
-                               conn_info->instance_id = 33;
-                               /* Append request info in list of requests for the particular connection */
-                               conn_info->gatt_req_info_list = g_slist_append(conn_info->gatt_req_info_list, req_info);
-                               gatt_client_info_list = g_slist_append(gatt_client_info_list, conn_info);
-
-                               /* Send HAL event */
-                               memset(&ev, 0, sizeof(ev));
-                               ev.conn_id = 33;
-                               ev.char_handl = char_hdl;
-                               ev.mtu = mtu;
-                               ev.trans_id = 33;
-
-                               event_cb(HAL_EV_GATT_SERVER_ACQUIRE_NOTIFY_RES, (void *)&ev, sizeof(ev));
-                               return;
+               if (svc_info == NULL) {
+                       ERR("svc_info  info not found\n");
+                       g_variant_iter_free(iter);
+                       goto done;
+               }
+
+               /* Store requets information */
+               req_info = g_new0(struct gatt_req_info, 1);
+               req_info->attr_path = g_strdup(object_path);
+               req_info->svc_path = g_strdup(svc_info->serv_path);
+               req_info->request_id = 33;
+               req_info->request_type = BT_HAL_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY;
+               req_info->offset = mtu;
+               req_info->context = invocation;
+
+               conn_info = g_new0(struct gatt_client_info_t, 1);
+               conn_info->addr = g_strdup(object_path);
+               INFO("AcquireNotify : Added GATT client path[%s]", conn_info->addr);
+               conn_info->connection_id = 33;
+               conn_info->instance_id = 33;
+               /* Append request info in list of requests for the particular connection */
+               conn_info->gatt_req_info_list = g_slist_append(conn_info->gatt_req_info_list, req_info);
+               gatt_client_info_list = g_slist_append(gatt_client_info_list, conn_info);
+
+               /* Send HAL event */
+               memset(&ev, 0, sizeof(ev));
+               ev.conn_id = 33;
+               ev.char_handl = char_hdl;
+               ev.mtu = mtu;
+               ev.trans_id = 33;
+
+               event_cb(HAL_EV_GATT_SERVER_ACQUIRE_NOTIFY_RES, (void *)&ev, sizeof(ev));
+               g_variant_iter_free(iter);
+               return;
        }
 
 done: