[gtksourceview/gnome-3-10] CompletionInfo: remove weak pointer



commit 867c716a664fca763e714f1da713d275b806a140
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Aug 25 22:47:12 2014 +0200

    CompletionInfo: remove weak pointer
    
    The weak pointer was not removed (!). Hopefully this didn't cause
    crashes, but Valgrind can detect the error.
    
    Thanks to Paolo for having catched the problem.

 gtksourceview/gtksourcecompletioninfo.c |   51 +++++++++++++++++-------------
 1 files changed, 29 insertions(+), 22 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 497dfc1..e6c9d16 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -208,17 +208,21 @@ focus_out_event_cb (GtkSourceCompletionInfo *info)
 }
 
 static void
-update_attached_to (GtkSourceCompletionInfo *info)
+set_attached_to (GtkSourceCompletionInfo *info,
+                GtkWidget               *attached_to)
 {
-       GtkWidget *attached_to = gtk_window_get_attached_to (GTK_WINDOW (info));
-
-       if (info->priv->focus_out_event_handler != 0 &&
-           info->priv->attached_to != NULL)
+       if (info->priv->attached_to != NULL)
        {
-               g_signal_handler_disconnect (info->priv->attached_to,
-                                            info->priv->focus_out_event_handler);
+               g_object_remove_weak_pointer (G_OBJECT (info->priv->attached_to),
+                                             (gpointer *) &info->priv->attached_to);
+
+               if (info->priv->focus_out_event_handler != 0)
+               {
+                       g_signal_handler_disconnect (info->priv->attached_to,
+                                                    info->priv->focus_out_event_handler);
 
-               info->priv->focus_out_event_handler = 0;
+                       info->priv->focus_out_event_handler = 0;
+               }
        }
 
        info->priv->attached_to = attached_to;
@@ -229,12 +233,19 @@ update_attached_to (GtkSourceCompletionInfo *info)
        }
 
        g_object_add_weak_pointer (G_OBJECT (attached_to),
-                                  (gpointer) &info->priv->attached_to);
+                                  (gpointer *) &info->priv->attached_to);
+
+       info->priv->focus_out_event_handler =
+               g_signal_connect_swapped (attached_to,
+                                         "focus-out-event",
+                                         G_CALLBACK (focus_out_event_cb),
+                                         info);
+}
 
-       info->priv->focus_out_event_handler = g_signal_connect_swapped (attached_to,
-                                                                       "focus-out-event",
-                                                                       G_CALLBACK (focus_out_event_cb),
-                                                                       info);
+static void
+update_attached_to (GtkSourceCompletionInfo *info)
+{
+       set_attached_to (info, gtk_window_get_attached_to (GTK_WINDOW (info)));
 }
 
 static void
@@ -260,23 +271,19 @@ gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
 }
 
 static void
-gtk_source_completion_info_finalize (GObject *object)
+gtk_source_completion_info_dispose (GObject *object)
 {
        GtkSourceCompletionInfo *info = GTK_SOURCE_COMPLETION_INFO (object);
 
        if (info->priv->idle_resize != 0)
        {
                g_source_remove (info->priv->idle_resize);
+               info->priv->idle_resize = 0;
        }
 
-       if (info->priv->focus_out_event_handler != 0 &&
-           info->priv->attached_to != NULL)
-       {
-               g_signal_handler_disconnect (info->priv->attached_to,
-                                            info->priv->focus_out_event_handler);
-       }
+       set_attached_to (info, NULL);
 
-       G_OBJECT_CLASS (gtk_source_completion_info_parent_class)->finalize (object);
+       G_OBJECT_CLASS (gtk_source_completion_info_parent_class)->dispose (object);
 }
 
 static void
@@ -310,7 +317,7 @@ gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
        GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
-       object_class->finalize = gtk_source_completion_info_finalize;
+       object_class->dispose = gtk_source_completion_info_dispose;
 
        widget_class->show = gtk_source_completion_info_show;
        widget_class->draw = gtk_source_completion_info_draw;


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