[network-manager-applet/NMA_0_8_1] editor: fix crash when cancelling addresses editing while in a cell (rh #610891)



commit 5665421edc73c47571a945c278646d097abb1cbb
Author: JiÅ?í KlimeÅ¡ <jklimes redhat com>
Date:   Mon Jul 26 10:37:43 2010 +0200

    editor: fix crash when cancelling addresses editing while in a cell (rh #610891)
    
    While editing addresses in IPv4 or IPv6 tab and a focus was in a cell, a crash could
    be caused by destroing the window clicking on x. The crash in cell_editing_canceled()
    callback occured due to disposed CEPageIP[4|6] object.

 src/connection-editor/page-ip4.c |   16 ++++++++++++++--
 src/connection-editor/page-ip6.c |   16 ++++++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index d1b449a..9c0f7f8 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -510,13 +510,20 @@ list_selection_changed (GtkTreeSelection *selection, gpointer user_data)
 static void
 cell_editing_canceled (GtkCellRenderer *renderer, gpointer user_data)
 {
-	CEPageIP4 *self = CE_PAGE_IP4 (user_data);
-	CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
+	CEPageIP4 *self;
+	CEPageIP4Private *priv;
 	GtkTreeModel *model = NULL;
 	GtkTreeSelection *selection;
 	GtkTreeIter iter;
 	guint32 column;
 
+	/* user_data disposed? */
+	if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (renderer), "ce-page-not-valid")))
+		return;
+
+	self = CE_PAGE_IP4 (user_data);
+	priv = CE_PAGE_IP4_GET_PRIVATE (self);
+
 	if (priv->last_edited) {
 		selection = gtk_tree_view_get_selection (priv->addr_list);
 		if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -1081,10 +1088,15 @@ dispose (GObject *object)
 {
 	CEPageIP4 *self = CE_PAGE_IP4 (object);
 	CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
+	int i;
 
 	if (priv->window_group)
 		g_object_unref (priv->window_group);
 
+	/* Mark CEPageIP4 object as invalid; store this indication to cells to be usable in callbacks */
+	for (i = 0; i <= COL_LAST; i++)
+		g_object_set_data (G_OBJECT (priv->addr_cells[i]), "ce-page-not-valid", GUINT_TO_POINTER (1));
+
 	g_free (priv->connection_id);
 
 	G_OBJECT_CLASS (ce_page_ip4_parent_class)->dispose (object);
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index 7b49ca2..cb4cd5c 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -483,13 +483,20 @@ list_selection_changed (GtkTreeSelection *selection, gpointer user_data)
 static void
 cell_editing_canceled (GtkCellRenderer *renderer, gpointer user_data)
 {
-	CEPageIP6 *self = CE_PAGE_IP6 (user_data);
-	CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
+	CEPageIP6 *self;
+	CEPageIP6Private *priv;
 	GtkTreeModel *model = NULL;
 	GtkTreeSelection *selection;
 	GtkTreeIter iter;
 	guint32 column;
 
+	/* user_data disposed? */
+	if (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (renderer), "ce-page-not-valid")))
+		return;
+
+	self = CE_PAGE_IP6 (user_data);
+	priv = CE_PAGE_IP6_GET_PRIVATE (self);
+
 	if (priv->last_edited) {
 		selection = gtk_tree_view_get_selection (priv->addr_list);
 		if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -989,10 +996,15 @@ dispose (GObject *object)
 {
 	CEPageIP6 *self = CE_PAGE_IP6 (object);
 	CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
+	int i;
 
 	if (priv->window_group)
 		g_object_unref (priv->window_group);
 
+	/* Mark CEPageIP6 object as invalid; store this indication to cells to be usable in callbacks */
+	for (i = 0; i <= COL_LAST; i++)
+		g_object_set_data (G_OBJECT (priv->addr_cells[i]), "ce-page-not-valid", GUINT_TO_POINTER (1));
+
 	g_free (priv->connection_id);
 
 	G_OBJECT_CLASS (ce_page_ip6_parent_class)->dispose (object);



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