[gnome-bluetooth] Prevent crash on removal of last device



commit 7292f79a500567a2fcccfd66d9cdead9f96584a4
Author: Joshua Lock <josh linux intel com>
Date:   Thu Oct 15 14:46:32 2009 +0100

    Prevent crash on removal of last device
    
    Calling gtk_tree_model_get with an uninitialised iter causes an assertion.
    Test the return value of gtk_tree_model_get_iter_first to verify whether we
    should try to get and data from the model.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=598590

 moblin/moblin-panel.c |   28 +++++++++++++++-------------
 1 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/moblin/moblin-panel.c b/moblin/moblin-panel.c
index 165ad82..d2130d9 100644
--- a/moblin/moblin-panel.c
+++ b/moblin/moblin-panel.c
@@ -883,27 +883,29 @@ static void
 have_connecting_device (MoblinPanel *self)
 {
 	MoblinPanelPrivate *priv = MOBLIN_PANEL_GET_PRIVATE (self);
-	GHashTable *states;
+	GHashTable *states = NULL;
 	GtkTreeIter iter;
 	BluetoothStatus status = BLUETOOTH_STATUS_INVALID;
 	gboolean connecting = FALSE;
 
-	gtk_tree_model_get_iter_first (priv->chooser_model, &iter);
-	gtk_tree_model_get(priv->chooser_model, &iter, BLUETOOTH_COLUMN_SERVICES, &states, -1);
+	if (gtk_tree_model_get_iter_first (priv->chooser_model, &iter) == TRUE)
+	{
+		gtk_tree_model_get(priv->chooser_model, &iter, BLUETOOTH_COLUMN_SERVICES, &states, -1);
 
-	if (states) {
-		g_hash_table_foreach (states, (GHFunc) determine_connecting, &status);
+		if (states) {
+			g_hash_table_foreach (states, (GHFunc) determine_connecting, &status);
 
-		g_hash_table_unref (states);
-	}
+			g_hash_table_unref (states);
+		}
 
-	if (status == BLUETOOTH_STATUS_CONNECTING)
-		connecting = TRUE;
+		if (status == BLUETOOTH_STATUS_CONNECTING)
+			connecting = TRUE;
 
-	if (connecting != priv->connecting) {
-		priv->connecting = connecting;
-		g_signal_emit (self, _signals[STATUS_CONNECTING], 0,
-			priv->connecting);
+		if (connecting != priv->connecting) {
+			priv->connecting = connecting;
+			g_signal_emit (self, _signals[STATUS_CONNECTING], 0,
+				priv->connecting);
+		}
 	}
 }
 



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