Merge lp:~3v1n0/bamf/unset-proxy-on-set-path into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño) on 2012-05-17
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2012-05-17
Approved revision: 464
Merged at revision: 463
Proposed branch: lp:~3v1n0/bamf/unset-proxy-on-set-path
Merge into: lp:bamf/0.4
Diff against target: 385 lines (+123/-126)
4 files modified
lib/libbamf/bamf-application.c (+32/-16)
lib/libbamf/bamf-indicator.c (+5/-0)
lib/libbamf/bamf-view.c (+58/-91)
lib/libbamf/bamf-window.c (+28/-19)
To merge this branch: bzr merge lp:~3v1n0/bamf/unset-proxy-on-set-path
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve on 2012-05-17
Andrea Azzarone (community) 2012-05-17 Approve on 2012-05-17
Review via email: mp+106117@code.launchpad.net

Commit message

libbamf: unset the previously defined proxy if adding a new one

This fixes some crashes, and memory leaks.

Description of the change

When setting an object path in libbamf, the previous proxy was never unreff'ed or disconnected by signals, this caused some crashes like bug #1000577.

Correctly unsetting the proxy and disconnecting from its signals, fixes the issue.

To post a comment you must log in.
Andrea Azzarone (azzar1) wrote :

LGTM

review: Approve
Tim Penhey (thumper) wrote :

I agree.

review: Approve
Unity Merger (unity-merger) wrote :

No commit message specified.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/libbamf/bamf-application.c'
2--- lib/libbamf/bamf-application.c 2012-04-26 17:11:45 +0000
3+++ lib/libbamf/bamf-application.c 2012-05-17 06:00:25 +0000
4@@ -249,6 +249,8 @@
5 BamfView *view;
6 BamfFactory *factory;
7
8+ g_return_if_fail (BAMF_IS_APPLICATION (self));
9+
10 factory = bamf_factory_get_default ();
11 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
12
13@@ -271,6 +273,8 @@
14 BamfView *view;
15 BamfFactory *factory;
16
17+ g_return_if_fail (BAMF_IS_APPLICATION (self));
18+
19 factory = bamf_factory_get_default ();
20 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
21
22@@ -292,6 +296,31 @@
23 }
24
25 static void
26+bamf_application_unset_proxy (BamfApplication* self)
27+{
28+ BamfApplicationPrivate *priv;
29+
30+ g_return_if_fail (BAMF_IS_APPLICATION (self));
31+ priv = self->priv;
32+
33+ if (!priv->proxy)
34+ return;
35+
36+ dbus_g_proxy_disconnect_signal (priv->proxy,
37+ "WindowAdded",
38+ (GCallback) bamf_application_on_window_added,
39+ self);
40+
41+ dbus_g_proxy_disconnect_signal (priv->proxy,
42+ "WindowRemoved",
43+ (GCallback) bamf_application_on_window_removed,
44+ self);
45+
46+ g_object_unref (priv->proxy);
47+ priv->proxy = NULL;
48+}
49+
50+static void
51 bamf_application_dispose (GObject *object)
52 {
53 BamfApplication *self;
54@@ -312,28 +341,14 @@
55 priv->desktop_file = NULL;
56 }
57
58- if (priv->proxy)
59- {
60- dbus_g_proxy_disconnect_signal (priv->proxy,
61- "WindowAdded",
62- (GCallback) bamf_application_on_window_added,
63- self);
64-
65- dbus_g_proxy_disconnect_signal (priv->proxy,
66- "WindowRemoved",
67- (GCallback) bamf_application_on_window_removed,
68- self);
69-
70- g_object_unref (priv->proxy);
71- priv->proxy = NULL;
72- }
73-
74 if (priv->cached_xids)
75 {
76 g_list_free (priv->cached_xids);
77 priv->cached_xids = NULL;
78 }
79
80+ bamf_application_unset_proxy (self);
81+
82 if (G_OBJECT_CLASS (bamf_application_parent_class)->dispose)
83 G_OBJECT_CLASS (bamf_application_parent_class)->dispose (object);
84 }
85@@ -347,6 +362,7 @@
86 self = BAMF_APPLICATION (view);
87 priv = self->priv;
88
89+ bamf_application_unset_proxy (self);
90 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
91 "org.ayatana.bamf",
92 path,
93
94=== modified file 'lib/libbamf/bamf-indicator.c'
95--- lib/libbamf/bamf-indicator.c 2010-10-26 03:48:12 +0000
96+++ lib/libbamf/bamf-indicator.c 2012-05-17 06:00:25 +0000
97@@ -214,6 +214,11 @@
98 self = BAMF_INDICATOR (view);
99 priv = self->priv;
100
101+ if (priv->proxy)
102+ {
103+ g_object_unref (priv->proxy);
104+ }
105+
106 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
107 "org.ayatana.bamf",
108 path,
109
110=== modified file 'lib/libbamf/bamf-view.c'
111--- lib/libbamf/bamf-view.c 2012-04-27 15:10:22 +0000
112+++ lib/libbamf/bamf-view.c 2012-05-17 06:00:25 +0000
113@@ -99,6 +99,8 @@
114 GList *cached_children;
115 };
116
117+static void bamf_view_unset_proxy (BamfView *self);
118+
119 static void
120 bamf_view_set_flag (BamfView *view, guint flag, gboolean value)
121 {
122@@ -567,46 +569,9 @@
123 priv->cached_children = NULL;
124 }
125
126- if (priv->sticky && priv->proxy)
127+ if (priv->sticky)
128 {
129- dbus_g_proxy_disconnect_signal (priv->proxy,
130- "ActiveChanged",
131- (GCallback) bamf_view_on_active_changed,
132- self);
133-
134- dbus_g_proxy_disconnect_signal (priv->proxy,
135- "Closed",
136- (GCallback) bamf_view_on_closed,
137- self);
138-
139- dbus_g_proxy_disconnect_signal (priv->proxy,
140- "ChildAdded",
141- (GCallback) bamf_view_on_child_added,
142- self);
143-
144- dbus_g_proxy_disconnect_signal (priv->proxy,
145- "ChildRemoved",
146- (GCallback) bamf_view_on_child_removed,
147- self);
148-
149- dbus_g_proxy_disconnect_signal (priv->proxy,
150- "RunningChanged",
151- (GCallback) bamf_view_on_running_changed,
152- self);
153-
154- dbus_g_proxy_disconnect_signal (priv->proxy,
155- "UrgentChanged",
156- (GCallback) bamf_view_on_urgent_changed,
157- self);
158-
159- dbus_g_proxy_disconnect_signal (priv->proxy,
160- "UserVisibleChanged",
161- (GCallback) bamf_view_on_user_visible_changed,
162- self);
163-
164- g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, self);
165- g_object_unref (priv->proxy);
166- priv->proxy = NULL;
167+ bamf_view_unset_proxy (self);
168 }
169
170 g_object_ref (self);
171@@ -668,6 +633,57 @@
172 }
173
174 static void
175+bamf_view_unset_proxy (BamfView *self)
176+{
177+ BamfViewPrivate *priv;
178+
179+ g_return_if_fail (BAMF_IS_VIEW (self));
180+ priv = self->priv;
181+
182+ if (!priv->proxy)
183+ return;
184+
185+ dbus_g_proxy_disconnect_signal (priv->proxy,
186+ "ActiveChanged",
187+ (GCallback) bamf_view_on_active_changed,
188+ self);
189+
190+ dbus_g_proxy_disconnect_signal (priv->proxy,
191+ "Closed",
192+ (GCallback) bamf_view_on_closed,
193+ self);
194+
195+ dbus_g_proxy_disconnect_signal (priv->proxy,
196+ "ChildAdded",
197+ (GCallback) bamf_view_on_child_added,
198+ self);
199+
200+ dbus_g_proxy_disconnect_signal (priv->proxy,
201+ "ChildRemoved",
202+ (GCallback) bamf_view_on_child_removed,
203+ self);
204+
205+ dbus_g_proxy_disconnect_signal (priv->proxy,
206+ "RunningChanged",
207+ (GCallback) bamf_view_on_running_changed,
208+ self);
209+
210+ dbus_g_proxy_disconnect_signal (priv->proxy,
211+ "UrgentChanged",
212+ (GCallback) bamf_view_on_urgent_changed,
213+ self);
214+
215+ dbus_g_proxy_disconnect_signal (priv->proxy,
216+ "UserVisibleChanged",
217+ (GCallback) bamf_view_on_user_visible_changed,
218+ self);
219+
220+ g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, self);
221+ g_object_unref (priv->proxy);
222+ priv->proxy = NULL;
223+}
224+
225+static void
226 bamf_view_dispose (GObject *object)
227 {
228 BamfView *view;
229@@ -688,7 +704,7 @@
230 g_free (priv->type);
231 priv->type = NULL;
232 }
233-
234+
235 if (priv->local_icon)
236 {
237 g_free (priv->local_icon);
238@@ -707,52 +723,7 @@
239 priv->cached_children = NULL;
240 }
241
242- if (priv->proxy)
243- {
244- dbus_g_proxy_disconnect_signal (priv->proxy,
245- "ActiveChanged",
246- (GCallback) bamf_view_on_active_changed,
247- view);
248-
249- dbus_g_proxy_disconnect_signal (priv->proxy,
250- "Closed",
251- (GCallback) bamf_view_on_closed,
252- view);
253-
254- dbus_g_proxy_disconnect_signal (priv->proxy,
255- "ChildAdded",
256- (GCallback) bamf_view_on_child_added,
257- view);
258-
259- dbus_g_proxy_disconnect_signal (priv->proxy,
260- "ChildRemoved",
261- (GCallback) bamf_view_on_child_removed,
262- view);
263-
264- dbus_g_proxy_disconnect_signal (priv->proxy,
265- "RunningChanged",
266- (GCallback) bamf_view_on_running_changed,
267- view);
268-
269- dbus_g_proxy_disconnect_signal (priv->proxy,
270- "UrgentChanged",
271- (GCallback) bamf_view_on_urgent_changed,
272- view);
273-
274- dbus_g_proxy_disconnect_signal (priv->proxy,
275- "UserVisibleChanged",
276- (GCallback) bamf_view_on_user_visible_changed,
277- view);
278-
279- dbus_g_proxy_disconnect_signal (priv->proxy,
280- "NameChanged",
281- (GCallback) bamf_view_on_name_changed,
282- view);
283-
284- g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, view);
285- g_object_unref (priv->proxy);
286- priv->proxy = NULL;
287- }
288+ bamf_view_unset_proxy (view);
289
290 G_OBJECT_CLASS (bamf_view_parent_class)->dispose (object);
291 }
292@@ -814,11 +785,7 @@
293 g_free (priv->path);
294 }
295
296- if (priv->proxy)
297- {
298- g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, view);
299- g_object_unref (priv->proxy);
300- }
301+ bamf_view_unset_proxy (view);
302
303 priv->path = g_strdup (path);
304 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
305
306=== modified file 'lib/libbamf/bamf-window.c'
307--- lib/libbamf/bamf-window.c 2012-04-26 17:11:45 +0000
308+++ lib/libbamf/bamf-window.c 2012-05-17 06:00:25 +0000
309@@ -228,6 +228,31 @@
310 }
311
312 static void
313+bamf_window_unset_proxy (BamfWindow *self)
314+{
315+ BamfWindowPrivate *priv;
316+
317+ g_return_if_fail (BAMF_IS_WINDOW (self));
318+ priv = self->priv;
319+
320+ if (!priv->proxy)
321+ return;
322+
323+ dbus_g_proxy_disconnect_signal (self->priv->proxy,
324+ "MaximizedChanged",
325+ (GCallback) bamf_window_on_maximized_changed,
326+ self);
327+
328+ dbus_g_proxy_disconnect_signal (self->priv->proxy,
329+ "MonitorChanged",
330+ (GCallback) bamf_window_on_monitor_changed,
331+ self);
332+
333+ g_object_unref (priv->proxy);
334+ priv->proxy = NULL;
335+}
336+
337+static void
338 bamf_window_set_path (BamfView *view, const char *path)
339 {
340 BamfWindow *self;
341@@ -236,6 +261,7 @@
342 self = BAMF_WINDOW (view);
343 priv = self->priv;
344
345+ bamf_window_unset_proxy (self);
346 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
347 "org.ayatana.bamf",
348 path,
349@@ -380,26 +406,9 @@
350 bamf_window_dispose (GObject *object)
351 {
352 BamfWindow *self;
353- BamfWindowPrivate *priv;
354
355 self = BAMF_WINDOW (object);
356- priv = self->priv;
357-
358- if (priv->proxy)
359- {
360- dbus_g_proxy_disconnect_signal (priv->proxy,
361- "MaximizedChanged",
362- (GCallback) bamf_window_on_maximized_changed,
363- self);
364-
365- dbus_g_proxy_disconnect_signal (priv->proxy,
366- "MonitorChanged",
367- (GCallback) bamf_window_on_monitor_changed,
368- self);
369-
370- g_object_unref (priv->proxy);
371- priv->proxy = NULL;
372- }
373+ bamf_window_unset_proxy (self);
374
375 if (G_OBJECT_CLASS (bamf_window_parent_class)->dispose)
376 G_OBJECT_CLASS (bamf_window_parent_class)->dispose (object);
377@@ -467,7 +476,7 @@
378 {
379 BamfWindow *self;
380 self = g_object_new (BAMF_TYPE_WINDOW, NULL);
381-
382+
383 bamf_view_set_path (BAMF_VIEW (self), path);
384
385 return self;

Subscribers

People subscribed via source and target branches