[epiphany/gnome-3-12] ephy-title-box: Fix crash when closing second window



commit c380040cbdd1f86d8d88c112d9d2f6fa1df31db4
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sat Jul 5 21:10:25 2014 -0500

    ephy-title-box: Fix crash when closing second window
    
    These binding could already have been destroyed. It might be safe to
    simply remove the calls to g_clear_object, since they are not needed for
    memory management, but then the bindings might not be unbound if a new
    web view is set before the old one is destroyed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732784

 src/ephy-title-box.c |   48 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/src/ephy-title-box.c b/src/ephy-title-box.c
index d08c5a8..ba00c6d 100644
--- a/src/ephy-title-box.c
+++ b/src/ephy-title-box.c
@@ -516,6 +516,36 @@ ephy_title_box_new (EphyWindow *window)
                        NULL);
 }
 
+static void
+ephy_title_box_title_binding_destroyed_cb (gpointer data)
+{
+  EphyTitleBox        *title_box;
+  EphyTitleBoxPrivate *priv;
+
+  title_box = EPHY_TITLE_BOX (data);
+  priv = ephy_title_box_get_instance_private (title_box);
+
+  LOG ("uri_binding_destroyed_cb title_box %p", title_box);
+
+  /* Indicate that we do not need to unbind this binding */
+  priv->title_binding = NULL;
+}
+
+static void
+ephy_title_box_uri_binding_destroyed_cb (gpointer data)
+{
+  EphyTitleBox        *title_box;
+  EphyTitleBoxPrivate *priv;
+
+  title_box = EPHY_TITLE_BOX (data);
+  priv = ephy_title_box_get_instance_private (title_box);
+
+  LOG ("uri_binding_destroyed_cb title_box %p", title_box);
+
+  /* Indicate that we do not need to unbind this binding */
+  priv->uri_binding = NULL;
+}
+
 /**
  * ephy_title_box_set_web_view:
  * @title_box: an #EphyTitleBox
@@ -549,8 +579,10 @@ ephy_title_box_set_web_view (EphyTitleBox  *title_box,
     if (priv->title_sig_id > 0)
       g_signal_handler_disconnect (priv->web_view, priv->title_sig_id);
 
-    g_clear_object (&priv->title_binding);
-    g_clear_object (&priv->uri_binding);
+    if (priv->title_binding != NULL)
+      g_clear_object (&priv->title_binding);
+    if (priv->uri_binding != NULL)
+      g_clear_object (&priv->uri_binding);
 
     g_object_unref (priv->web_view);
   }
@@ -567,15 +599,17 @@ ephy_title_box_set_web_view (EphyTitleBox  *title_box,
   ephy_title_box_set_mode (title_box, title && *title != '\0' ?
                                       EPHY_TITLE_BOX_MODE_TITLE : EPHY_TITLE_BOX_MODE_LOCATION_ENTRY);
 
-  priv->title_binding = g_object_bind_property (priv->web_view, "title",
-                                                priv->title, "label",
-                                                G_BINDING_SYNC_CREATE);
+  priv->title_binding = g_object_bind_property_full (priv->web_view, "title",
+                                                     priv->title, "label",
+                                                     G_BINDING_SYNC_CREATE,
+                                                     NULL, NULL,
+                                                     title_box, ephy_title_box_title_binding_destroyed_cb);
 
   priv->uri_binding = g_object_bind_property_full (priv->web_view, "uri",
                                                    priv->uri, "label",
                                                    G_BINDING_SYNC_CREATE,
-                                                   ephy_title_box_transform_uri_to_label,
-                                                   NULL, NULL, NULL);
+                                                   ephy_title_box_transform_uri_to_label, NULL,
+                                                   title_box, ephy_title_box_uri_binding_destroyed_cb);
 
   priv->title_sig_id = g_signal_connect (priv->web_view, "notify::title",
                                          G_CALLBACK (ephy_title_box_title_changed_cb),


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