Fix the crash of socket disconnection 76/27076/1
authorwu zheng <wu.zheng@intel.com>
Thu, 4 Sep 2014 06:59:42 +0000 (14:59 +0800)
committerwu zheng <wu.zheng@intel.com>
Thu, 4 Sep 2014 06:59:42 +0000 (14:59 +0800)
When socket disconnection, channel is needed to report fd handle.
However, channel has been removed.
It results in the crash and fix it.

BTW, remove unuseful source code.

Change-Id: I8cfd02e7fd6dddd6e5540dc18acbc22f3031ece4
Signed-off-by: Wu Zheng <wu.zheng@intel.com>
capi/bluetooth.c

index 76c983a..828c48b 100644 (file)
@@ -3830,7 +3830,7 @@ static void notify_connection_state(gchar *device_path,
 
        fd = g_io_channel_unix_get_fd(spp_ctx->channel);
 
-       if (spp_ctx->new_connection)
+       if (spp_ctx->new_connection && state == BT_SOCKET_CONNECTED)
                spp_ctx->new_connection(spp_ctx->uuid, device_name,
                                        fd, spp_ctx->new_connection_data);
 
@@ -3897,11 +3897,11 @@ static void handle_request_disconnection(gchar *device_path,
 
        DBG("device path %s", device_path);
 
+       notify_connection_state(device_path, BT_SOCKET_DISCONNECTED, spp_ctx);
+
        g_io_channel_unref(spp_ctx->channel);
        spp_ctx->channel = NULL;
 
-       notify_connection_state(device_path, BT_SOCKET_DISCONNECTED, spp_ctx);
-
        g_dbus_method_invocation_return_value(invocation, NULL);
 }
 
@@ -4519,8 +4519,6 @@ int bt_socket_set_connection_state_changed_cb(
        socket_connection_state_node = node_data;
 
        return BT_SUCCESS;
-
-       return BT_SUCCESS;
 }
 
 int bt_socket_unset_connection_requested_cb(void)