[gnome-control-center] bluetooth: Fix crash when exiting during a connection



commit ba4eb4277889acdc2c6b3bf29095fad93f3dbb9c
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Sep 20 19:04:07 2013 +0200

    bluetooth: Fix crash when exiting during a connection
    
    If a connection is on-going, make sure to cancel it before
    when finalizing the panel, or we will be crashing once
    we've finished connecting/disconnecting.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=708478

 panels/bluetooth/cc-bluetooth-panel.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/panels/bluetooth/cc-bluetooth-panel.c b/panels/bluetooth/cc-bluetooth-panel.c
index 409d4cf..95d008e 100644
--- a/panels/bluetooth/cc-bluetooth-panel.c
+++ b/panels/bluetooth/cc-bluetooth-panel.c
@@ -60,6 +60,7 @@ struct CcBluetoothPanelPrivate {
        gboolean             debug;
        GHashTable          *connecting_devices;
        GtkWidget           *kill_switch_header;
+       GCancellable        *cancellable;
 };
 
 static void cc_bluetooth_panel_finalize (GObject *object);
@@ -104,6 +105,9 @@ cc_bluetooth_panel_finalize (GObject *object)
        bluetooth_plugin_manager_cleanup ();
 
        self = CC_BLUETOOTH_PANEL (object);
+       g_cancellable_cancel (self->priv->cancellable);
+       g_clear_object (&self->priv->cancellable);
+
        g_clear_object (&self->priv->builder);
        g_clear_object (&self->priv->killswitch);
        g_clear_object (&self->priv->client);
@@ -168,10 +172,13 @@ connect_done (GObject      *source_object,
        CcBluetoothPanel *self;
        char *bdaddr;
        gboolean success;
+       GError *error = NULL;
        ConnectData *data = (ConnectData *) user_data;
 
        success = bluetooth_client_connect_service_finish (BLUETOOTH_CLIENT (source_object),
-                                                          res, NULL);
+                                                          res, &error);
+       if (!success && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+               goto out;
 
        self = data->self;
 
@@ -190,7 +197,9 @@ connect_done (GObject      *source_object,
        remove_connecting (self, data->bdaddr);
 
        g_free (bdaddr);
-       g_object_unref (data->self);
+
+out:
+       g_clear_error (&error);
        g_free (data->bdaddr);
        g_free (data);
 }
@@ -224,12 +233,12 @@ switch_connected_active_changed (GtkSwitch        *button,
 
        data = g_new0 (ConnectData, 1);
        data->bdaddr = bdaddr;
-       data->self = g_object_ref (self);
+       data->self = self;
 
        bluetooth_client_connect_service (self->priv->client,
                                          proxy,
                                          gtk_switch_get_active (button),
-                                         NULL,
+                                         self->priv->cancellable,
                                          connect_done,
                                          data);
 
@@ -787,6 +796,7 @@ cc_bluetooth_panel_init (CcBluetoothPanel *self)
        g_resources_register (cc_bluetooth_get_resource ());
 
        bluetooth_plugin_manager_init ();
+       self->priv->cancellable = g_cancellable_new ();
        self->priv->killswitch = bluetooth_killswitch_new ();
        self->priv->client = bluetooth_client_new ();
        self->priv->connecting_devices = g_hash_table_new_full (g_str_hash,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]