Fix bluetoothd crash on stopping device discovery 32/173032/1
authorAtul Rai <a.rai@samsung.com>
Wed, 14 Mar 2018 11:45:09 +0000 (17:15 +0530)
committerAtul Rai <a.rai@samsung.com>
Mon, 19 Mar 2018 08:35:29 +0000 (14:05 +0530)
Change-Id: Ic95272adc88d83af0aa98e3f7290d9f3dd15dd86
Signed-off-by: Atul Rai <a.rai@samsung.com>
src/adapter.c

index 8adbad1..3cb315d 100644 (file)
@@ -1918,9 +1918,6 @@ static void start_discovery_complete(uint8_t status, uint16_t length,
        DBusMessage *reply;
 
        DBG("status 0x%02x", status);
-#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
-       DBG("status 0x%02x", status);
-#endif
 
        /* Is there are no clients the discovery must have been stopped while
         * discovery command was pending.
@@ -2526,25 +2523,42 @@ static void discovery_remove(struct watch_client *client)
 static void stop_discovery_complete(uint8_t status, uint16_t length,
                                        const void *param, void *user_data)
 {
-       struct btd_adapter *adapter = user_data;
+       struct watch_client *client = user_data;
+       struct btd_adapter *adapter = client->adapter;
+       DBusMessage *reply;
 
        DBG("status 0x%02x", status);
 
-       if (status == MGMT_STATUS_SUCCESS) {
-               adapter->discovery_type &= (~0x01);
-               DBG("Discovery Type 0x%02x", adapter->discovery_type);
+       if (status != MGMT_STATUS_SUCCESS) {
+               if (client->msg) {
+                       reply = btd_error_busy(client->msg);
+                       g_dbus_send_message(dbus_conn, reply);
+               }
 
-               adapter->filtered_discovery = false;
-               adapter->no_scan_restart_delay = false;
-               adapter->discovering = false;
-               g_dbus_emit_property_changed(dbus_conn, adapter->path,
-                                       ADAPTER_INTERFACE, "Discovering");
+               goto done;
+       }
 
-               if (adapter->discovery_list == NULL && adapter->le_discovery_list == NULL) {
-                       adapter->discovery_enable = 0x00;
-                       trigger_passive_scanning(adapter);
-               }
+       if (client->msg) {
+               reply = g_dbus_create_reply(client->msg, DBUS_TYPE_INVALID);
+               g_dbus_send_message(dbus_conn, reply);
        }
+
+       adapter->discovery_type &= (~0x01);
+       DBG("Discovery Type 0x%02x", adapter->discovery_type);
+
+       adapter->filtered_discovery = false;
+       adapter->no_scan_restart_delay = false;
+       adapter->discovering = false;
+       g_dbus_emit_property_changed(dbus_conn, adapter->path,
+                       ADAPTER_INTERFACE, "Discovering");
+
+       if (adapter->discovery_list == NULL && adapter->le_discovery_list == NULL) {
+               adapter->discovery_enable = 0x00;
+               trigger_passive_scanning(adapter);
+       }
+
+done:
+       discovery_remove(client);
 }
 
 static void stop_le_discovery_complete(uint8_t status, uint16_t length,
@@ -3033,7 +3047,7 @@ static void le_discovery_disconnect(DBusConnection *conn, void *user_data)
 
        mgmt_send(adapter->mgmt, MGMT_OP_STOP_LE_DISCOVERY,
                                adapter->dev_id, sizeof(cp), &cp,
-                               stop_discovery_complete, adapter, NULL);
+                               stop_discovery_complete, client, NULL);
 }
 
 #ifdef TIZEN_FEATURE_PLATFROM_SCAN_FILTER