Fix wrong index usage issue 35/230935/1
authorWootak Jung <wootak.jung@samsung.com>
Thu, 16 Apr 2020 05:54:15 +0000 (14:54 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 16 Apr 2020 06:23:01 +0000 (15:23 +0900)
service removed event is not occured when server app is terminated
in case array index of numapps is mismatched with instance id

Change-Id: Ieaac786792f1adf01d1d1e45e78d31ddcca03f1c

bt-service-adaptation/services/gatt/bt-service-gatt.c

index 737740d..e97a990 100644 (file)
@@ -341,7 +341,7 @@ void _bt_check_adv_app_termination(const char *name)
 
                /* Search for a app which has same sender and stop adv is running */
                if (!strncasecmp(app->sender, name, strlen(name)) && app->is_initialized == TRUE) {
-                       BT_DBG("Match found, name: %s", name);
+                       BT_DBG("numapps[%d] Match found, name: %s", k, name);
 
                        /* TODO 2: Need to manage app info as list, not array.
                                   This loop always run for MAX count if any apps are terminated.
@@ -1229,7 +1229,7 @@ static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
                info = &numapps[k];
 
                if (info->instance_id == event->gatt_srvc_stat.server_inst) {
-                       BT_INFO("Found GATT Server.. UUID [%s], sender [%s]", info->uuid, info->sender);
+                       BT_INFO("numapps[%d] Found GATT Server.. UUID [%s], sender [%s]", k, info->uuid, info->sender);
                        __bt_gatt_handle_pending_request_info(result, BT_GATT_SERVER_ADD_SERVICE,
                                        (int*)&svc_handle, sizeof(int));
 
@@ -1237,8 +1237,8 @@ static void __bt_handle_gatt_server_service_added(event_gatts_srvc_prm_t *event)
                        if (svc_handle > 0) {
                                handle = g_malloc0(sizeof(int));
                                *handle = svc_handle;
-                               numapps[event->gatt_srvc_stat.server_inst].service_handles = g_slist_append(numapps[event->gatt_srvc_stat.server_inst].service_handles, handle);
-                               count = g_slist_length(numapps[event->gatt_srvc_stat.server_inst].service_handles);
+                               numapps[k].service_handles = g_slist_append(numapps[k].service_handles, handle);
+                               count = g_slist_length(numapps[k].service_handles);
                                BT_INFO("Added Service handle [%d] to list..current count [%d]", svc_handle, count);
                        }
                        break;