[unique] [app] Remove weak ref on watched windows



commit de65189c7cb4969a1c68ad6fa2d2aca7a9eba5f7
Author: Armin Burgmeier <armin arbur net>
Date:   Sun May 3 15:08:37 2009 +0100

    [app] Remove weak ref on watched windows
    
    Fixes a crash when a watched window is freed after the UniqueApp
    was freed.
    
    Signed-off-by: Emmanuele Bassi <ebassi gnome org>

 unique/uniqueapp.c |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)
---
diff --git a/unique/uniqueapp.c b/unique/uniqueapp.c
index 56257c5..0587233 100644
--- a/unique/uniqueapp.c
+++ b/unique/uniqueapp.c
@@ -291,6 +291,16 @@ unique_app_real_message_received (UniqueApp         *app,
   return UNIQUE_RESPONSE_OK;
 }
 
+static void
+window_weak_ref_cb (gpointer  user_data,
+                    GObject  *dead_object)
+{
+  UniqueApp *app = user_data;
+  UniqueAppPrivate *priv = app->priv;
+
+  priv->windows = g_slist_remove (priv->windows, dead_object);
+}
+
 static GObject *
 unique_app_constructor (GType                  gtype,
                         guint                  n_params,
@@ -391,6 +401,7 @@ unique_app_finalize (GObject *gobject)
 {
   UniqueApp *app = UNIQUE_APP (gobject);
   UniqueAppPrivate *priv = app->priv;
+  GSList *l;
 
   if (priv->commands_by_name)
     g_hash_table_destroy (priv->commands_by_name);
@@ -398,8 +409,10 @@ unique_app_finalize (GObject *gobject)
   if (priv->commands_by_id)
     g_hash_table_destroy (priv->commands_by_id);
 
-  if (priv->windows)
-    g_slist_free (priv->windows);
+  for (l = priv->windows; l != NULL; l = l->next)
+    g_object_weak_unref (l->data, window_weak_ref_cb, app);
+
+  g_slist_free (priv->windows);
 
   G_OBJECT_CLASS (unique_app_parent_class)->finalize (gobject);
 }
@@ -787,16 +800,6 @@ unique_app_add_command (UniqueApp   *app,
                         command_nick);
 }
 
-static void
-window_weak_ref_cb (gpointer  user_data,
-                    GObject  *object)
-{
-  UniqueApp *app = user_data;
-  UniqueAppPrivate *priv = app->priv;
-
-  priv->windows = g_slist_remove (priv->windows, object);
-}
-
 /**
  * unique_app_watch_window:
  * @app: a #UniqueApp



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