Merge lp:~charlesk/overlay-scrollbar/lp-1058205 into lp:overlay-scrollbar

Proposed by Charles Kerr
Status: Merged
Merged at revision: 357
Proposed branch: lp:~charlesk/overlay-scrollbar/lp-1058205
Merge into: lp:overlay-scrollbar
Diff against target: 151 lines (+66/-48)
1 file modified
os/os-scrollbar.c (+66/-48)
To merge this branch: bzr merge lp:~charlesk/overlay-scrollbar/lp-1058205
Reviewer Review Type Date Requested Status
jenkins (community) continuous-integration Approve
Thomas Bechtold (community) Approve
Andrea Cimitan Approve
Review via email: mp+128087@code.launchpad.net

Description of the change

This is based off Thomas' fix-mem-leak-bug-1058205 branch.

While I was testing Thomas' branch, I noticed his test case reported the overlay scrollbar created these Priv structs while the scrollbars were being disposed. This has two problems -- first is the unnecessary work of creating and populating a Priv struct only to dispose it; but more importantly, we're allocating memory and setting it in an object's qdata after the object's been disposed.

So, this branch contains Thomas' slice_free() fix and also avoids creating Privs in our hijacked_scrollbar_dispose() callback.

To post a comment you must log in.
Revision history for this message
Andrea Cimitan (cimi) wrote :

Fine for me, there's an extra white line before the new static function :)

review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Thomas Bechtold (toabctl) wrote :

Looks good to me. The Jenkins links are all 404 :(

review: Approve
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'os/os-scrollbar.c'
2--- os/os-scrollbar.c 2012-08-29 16:09:23 +0000
3+++ os/os-scrollbar.c 2012-10-04 18:48:20 +0000
4@@ -607,14 +607,29 @@
5 }
6 #endif
7
8-/* Get the private struct. */
9+
10+/* destroy the private struct */
11+static void
12+destroy_private (gpointer priv)
13+{
14+ g_slice_free (OsScrollbarPrivate, priv);
15+}
16+
17+/* Get the private struct. If there isn't one, return NULL */
18+static OsScrollbarPrivate*
19+lookup_private (GtkWidget *widget)
20+{
21+ return g_object_get_qdata (G_OBJECT (widget), os_quark_qdata);
22+}
23+
24+/* Get the private struct. If there isn't one, create it */
25 static OsScrollbarPrivate*
26 get_private (GtkWidget *widget)
27 {
28 OsScrollbarPrivate *priv;
29
30 /* Fetch the private qdata struct. */
31- priv = g_object_get_qdata (G_OBJECT (widget), os_quark_qdata);
32+ priv = lookup_private (widget);
33
34 if (!priv)
35 {
36@@ -665,7 +680,7 @@
37 scrolling_cb, scrolling_end_cb, widget);
38
39 /* Store qdata. */
40- g_object_set_qdata (G_OBJECT (widget), os_quark_qdata, qdata);
41+ g_object_set_qdata_full (G_OBJECT (widget), os_quark_qdata, qdata, destroy_private);
42 priv = qdata;
43
44 /* Create adjustment and thumb. */
45@@ -3173,31 +3188,6 @@
46 OsScrollbarPrivate *priv;
47
48 scrollbar = GTK_SCROLLBAR (object);
49- priv = get_private (GTK_WIDGET (scrollbar));
50-
51- if (priv->source_deactivate_bar_id != 0)
52- {
53- g_source_remove (priv->source_deactivate_bar_id);
54- priv->source_deactivate_bar_id = 0;
55- }
56-
57- if (priv->source_hide_thumb_id != 0)
58- {
59- g_source_remove (priv->source_hide_thumb_id);
60- priv->source_hide_thumb_id = 0;
61- }
62-
63- if (priv->source_show_thumb_id != 0)
64- {
65- g_source_remove (priv->source_show_thumb_id);
66- priv->source_show_thumb_id = 0;
67- }
68-
69- if (priv->source_unlock_thumb_id != 0)
70- {
71- g_source_remove (priv->source_unlock_thumb_id);
72- priv->source_unlock_thumb_id = 0;
73- }
74
75 os_root_list = g_slist_remove (os_root_list, scrollbar);
76
77@@ -3213,26 +3203,54 @@
78 root_filter_func, NULL);
79 }
80
81- if (priv->animation != NULL)
82- {
83- g_object_unref (priv->animation);
84- priv->animation = NULL;
85- }
86-
87- if (priv->bar != NULL)
88- {
89- g_object_unref (priv->bar);
90- priv->bar = NULL;
91- }
92-
93- if (priv->window_group != NULL)
94- {
95- g_object_unref (priv->window_group);
96- priv->window_group = NULL;
97- }
98-
99- swap_adjustment (scrollbar, NULL);
100- swap_thumb (scrollbar, NULL);
101+ priv = lookup_private (GTK_WIDGET(scrollbar));
102+ if (priv != NULL)
103+ {
104+ if (priv->source_deactivate_bar_id != 0)
105+ {
106+ g_source_remove (priv->source_deactivate_bar_id);
107+ priv->source_deactivate_bar_id = 0;
108+ }
109+
110+ if (priv->source_hide_thumb_id != 0)
111+ {
112+ g_source_remove (priv->source_hide_thumb_id);
113+ priv->source_hide_thumb_id = 0;
114+ }
115+
116+ if (priv->source_show_thumb_id != 0)
117+ {
118+ g_source_remove (priv->source_show_thumb_id);
119+ priv->source_show_thumb_id = 0;
120+ }
121+
122+ if (priv->source_unlock_thumb_id != 0)
123+ {
124+ g_source_remove (priv->source_unlock_thumb_id);
125+ priv->source_unlock_thumb_id = 0;
126+ }
127+
128+ if (priv->animation != NULL)
129+ {
130+ g_object_unref (priv->animation);
131+ priv->animation = NULL;
132+ }
133+
134+ if (priv->bar != NULL)
135+ {
136+ g_object_unref (priv->bar);
137+ priv->bar = NULL;
138+ }
139+
140+ if (priv->window_group != NULL)
141+ {
142+ g_object_unref (priv->window_group);
143+ priv->window_group = NULL;
144+ }
145+
146+ swap_adjustment (scrollbar, NULL);
147+ swap_thumb (scrollbar, NULL);
148+ }
149 }
150
151 (* pre_hijacked_scrollbar_dispose) (object);

Subscribers

People subscribed via source and target branches