Merge lp:~cimi/overlay-scrollbar/various-fixes-to-mem-leaks-and-dispose into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 202
Merged at revision: 201
Proposed branch: lp:~cimi/overlay-scrollbar/various-fixes-to-mem-leaks-and-dispose
Merge into: lp:overlay-scrollbar
Diff against target: 135 lines (+44/-18)
3 files modified
os/os-pager.c (+18/-0)
os/os-scrollbar.c (+3/-9)
os/os-thumb.c (+23/-9)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/various-fixes-to-mem-leaks-and-dispose
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+56800@code.launchpad.net

Description of the change

A lot of object were not freed/disposed/unref

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

  review needsfixing

On Thu, 2011-04-07 at 16:18 +0000, Andrea Cimitan wrote:
> @@ -265,6 +267,20 @@
> priv->animation = NULL;
> }
>
> + if (priv->pager_window != NULL)
> + {
> + /* FIXME(Cimi) g_object_destroy doesn't seem
> + * to clear the background.
> + * Maybe I need to clear it using cairo,
> + * but gdk_window_destroy() does this for me. */
> + gdk_window_destroy (priv->pager_window);
> +
> + g_object_unref (priv->pager_window);
> + priv->pager_window = NULL;

You shouldn't need to destroy and unref. That could cause problems.

> + if (priv->grabbed_widget != NULL)
> + g_object_unref (priv->grabbed_widget);
> +
> priv->grabbed_widget = gtk_grab_get_current ();
>
> if (priv->grabbed_widget != NULL)
> - gtk_grab_remove (priv->grabbed_widget);
> + {
> + g_object_ref_sink (priv->grabbed_widget);
> +
> + gtk_grab_remove (priv->grabbed_widget);
> + }
>
> GTK_WIDGET_CLASS (os_thumb_parent_class)->map (widget);
> }

After unref'ing the grabbed_widget you need to set it to NULL otherwise
the if won't work correctly.

review: Needs Fixing
202. By Andrea Cimitan

updated comment

Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'os/os-pager.c'
2--- os/os-pager.c 2011-04-06 16:18:11 +0000
3+++ os/os-pager.c 2011-04-07 17:16:07 +0000
4@@ -104,6 +104,8 @@
5 &attributes,
6 GDK_WA_VISUAL | GDK_WA_COLORMAP);
7
8+ g_object_ref_sink (priv->pager_window);
9+
10 gdk_window_set_transient_for (priv->pager_window,
11 gtk_widget_get_window (priv->parent));
12
13@@ -265,6 +267,22 @@
14 priv->animation = NULL;
15 }
16
17+ if (priv->pager_window != NULL)
18+ {
19+ /* From the Gdk documentation:
20+ * "Note that a window will not be destroyed
21+ * automatically when its reference count
22+ * reaches zero. You must call
23+ * gdk_window_destroy ()
24+ * yourself before that happens". */
25+ gdk_window_destroy (priv->pager_window);
26+
27+ g_object_unref (priv->pager_window);
28+ priv->pager_window = NULL;
29+ }
30+
31+ os_pager_set_parent (pager, NULL);
32+
33 g_signal_handler_disconnect (gtk_settings_get_default (),
34 priv->handler_id);
35
36
37=== modified file 'os/os-scrollbar.c'
38--- os/os-scrollbar.c 2011-04-07 13:36:15 +0000
39+++ os/os-scrollbar.c 2011-04-07 17:16:07 +0000
40@@ -1438,21 +1438,15 @@
41 priv->pager = NULL;
42 }
43
44+ os_scrollbar_swap_adjustment (scrollbar, NULL);
45+ os_scrollbar_swap_thumb (scrollbar, NULL);
46+
47 G_OBJECT_CLASS (os_scrollbar_parent_class)->dispose (object);
48 }
49
50 static void
51 os_scrollbar_finalize (GObject *object)
52 {
53- OsScrollbar *scrollbar;
54- OsScrollbarPrivate *priv;
55-
56- scrollbar = OS_SCROLLBAR (object);
57- priv = scrollbar->priv;
58-
59- os_scrollbar_swap_adjustment (scrollbar, NULL);
60- os_scrollbar_swap_thumb (scrollbar, NULL);
61-
62 G_OBJECT_CLASS (os_scrollbar_parent_class)->finalize (object);
63 }
64
65
66=== modified file 'os/os-thumb.c'
67--- os/os-thumb.c 2011-04-06 10:54:14 +0000
68+++ os/os-thumb.c 2011-04-07 17:16:07 +0000
69@@ -161,10 +161,10 @@
70 widget_class->unmap = os_thumb_unmap;
71
72 gobject_class->constructor = os_thumb_constructor;
73+ gobject_class->dispose = os_thumb_dispose;
74+ gobject_class->finalize = os_thumb_finalize;
75 gobject_class->get_property = os_thumb_get_property;
76 gobject_class->set_property = os_thumb_set_property;
77- gobject_class->dispose = os_thumb_dispose;
78- gobject_class->finalize = os_thumb_finalize;
79
80 g_object_class_install_property
81 (gobject_class, PROP_ORIENTATION,
82@@ -230,6 +230,12 @@
83 priv->animation = NULL;
84 }
85
86+ if (priv->grabbed_widget != NULL)
87+ {
88+ g_object_unref (priv->grabbed_widget);
89+ priv->grabbed_widget = NULL;
90+ }
91+
92 G_OBJECT_CLASS (os_thumb_parent_class)->dispose (object);
93 }
94
95@@ -291,14 +297,15 @@
96 thumb = OS_THUMB (widget);
97 priv = thumb->priv;
98
99- OS_DCHECK (priv->source_id == 0);
100-
101 gtk_widget_get_allocation (widget, &allocation);
102
103- /* priv->source_id should be always 0 here,
104- * because it's set to 0 in both motion_notify_event
105- * and button_press_event.
106- * Add the fade-out timeout only
107+ if (priv->source_id != 0)
108+ {
109+ g_source_remove (priv->source_id);
110+ priv->source_id = 0;
111+ }
112+
113+ /* Add the fade-out timeout only
114 * if the pointer is inside the thumb.
115 * allocation.x and allocation.y are always 0. */
116 if ((event->x >= 0 && event->x <= allocation.width) &&
117@@ -595,10 +602,17 @@
118
119 gtk_window_set_opacity (GTK_WINDOW (widget), 1.0f);
120
121+ if (priv->grabbed_widget != NULL)
122+ g_object_unref (priv->grabbed_widget);
123+
124 priv->grabbed_widget = gtk_grab_get_current ();
125
126 if (priv->grabbed_widget != NULL)
127- gtk_grab_remove (priv->grabbed_widget);
128+ {
129+ g_object_ref_sink (priv->grabbed_widget);
130+
131+ gtk_grab_remove (priv->grabbed_widget);
132+ }
133
134 GTK_WIDGET_CLASS (os_thumb_parent_class)->map (widget);
135 }

Subscribers

People subscribed via source and target branches