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
=== modified file 'lib/libbamf/bamf-application.c'
--- lib/libbamf/bamf-application.c 2012-04-26 17:11:45 +0000
+++ lib/libbamf/bamf-application.c 2012-05-17 06:00:25 +0000
@@ -249,6 +249,8 @@
249 BamfView *view;249 BamfView *view;
250 BamfFactory *factory;250 BamfFactory *factory;
251251
252 g_return_if_fail (BAMF_IS_APPLICATION (self));
253
252 factory = bamf_factory_get_default ();254 factory = bamf_factory_get_default ();
253 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);255 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
254256
@@ -271,6 +273,8 @@
271 BamfView *view;273 BamfView *view;
272 BamfFactory *factory;274 BamfFactory *factory;
273275
276 g_return_if_fail (BAMF_IS_APPLICATION (self));
277
274 factory = bamf_factory_get_default ();278 factory = bamf_factory_get_default ();
275 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);279 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
276280
@@ -292,6 +296,31 @@
292}296}
293297
294static void298static void
299bamf_application_unset_proxy (BamfApplication* self)
300{
301 BamfApplicationPrivate *priv;
302
303 g_return_if_fail (BAMF_IS_APPLICATION (self));
304 priv = self->priv;
305
306 if (!priv->proxy)
307 return;
308
309 dbus_g_proxy_disconnect_signal (priv->proxy,
310 "WindowAdded",
311 (GCallback) bamf_application_on_window_added,
312 self);
313
314 dbus_g_proxy_disconnect_signal (priv->proxy,
315 "WindowRemoved",
316 (GCallback) bamf_application_on_window_removed,
317 self);
318
319 g_object_unref (priv->proxy);
320 priv->proxy = NULL;
321}
322
323static void
295bamf_application_dispose (GObject *object)324bamf_application_dispose (GObject *object)
296{325{
297 BamfApplication *self;326 BamfApplication *self;
@@ -312,28 +341,14 @@
312 priv->desktop_file = NULL;341 priv->desktop_file = NULL;
313 }342 }
314343
315 if (priv->proxy)
316 {
317 dbus_g_proxy_disconnect_signal (priv->proxy,
318 "WindowAdded",
319 (GCallback) bamf_application_on_window_added,
320 self);
321
322 dbus_g_proxy_disconnect_signal (priv->proxy,
323 "WindowRemoved",
324 (GCallback) bamf_application_on_window_removed,
325 self);
326
327 g_object_unref (priv->proxy);
328 priv->proxy = NULL;
329 }
330
331 if (priv->cached_xids)344 if (priv->cached_xids)
332 {345 {
333 g_list_free (priv->cached_xids);346 g_list_free (priv->cached_xids);
334 priv->cached_xids = NULL;347 priv->cached_xids = NULL;
335 }348 }
336349
350 bamf_application_unset_proxy (self);
351
337 if (G_OBJECT_CLASS (bamf_application_parent_class)->dispose)352 if (G_OBJECT_CLASS (bamf_application_parent_class)->dispose)
338 G_OBJECT_CLASS (bamf_application_parent_class)->dispose (object);353 G_OBJECT_CLASS (bamf_application_parent_class)->dispose (object);
339}354}
@@ -347,6 +362,7 @@
347 self = BAMF_APPLICATION (view);362 self = BAMF_APPLICATION (view);
348 priv = self->priv;363 priv = self->priv;
349364
365 bamf_application_unset_proxy (self);
350 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,366 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
351 "org.ayatana.bamf",367 "org.ayatana.bamf",
352 path,368 path,
353369
=== modified file 'lib/libbamf/bamf-indicator.c'
--- lib/libbamf/bamf-indicator.c 2010-10-26 03:48:12 +0000
+++ lib/libbamf/bamf-indicator.c 2012-05-17 06:00:25 +0000
@@ -214,6 +214,11 @@
214 self = BAMF_INDICATOR (view);214 self = BAMF_INDICATOR (view);
215 priv = self->priv;215 priv = self->priv;
216216
217 if (priv->proxy)
218 {
219 g_object_unref (priv->proxy);
220 }
221
217 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,222 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
218 "org.ayatana.bamf",223 "org.ayatana.bamf",
219 path,224 path,
220225
=== modified file 'lib/libbamf/bamf-view.c'
--- lib/libbamf/bamf-view.c 2012-04-27 15:10:22 +0000
+++ lib/libbamf/bamf-view.c 2012-05-17 06:00:25 +0000
@@ -99,6 +99,8 @@
99 GList *cached_children;99 GList *cached_children;
100};100};
101101
102static void bamf_view_unset_proxy (BamfView *self);
103
102static void104static void
103bamf_view_set_flag (BamfView *view, guint flag, gboolean value)105bamf_view_set_flag (BamfView *view, guint flag, gboolean value)
104{106{
@@ -567,46 +569,9 @@
567 priv->cached_children = NULL;569 priv->cached_children = NULL;
568 }570 }
569571
570 if (priv->sticky && priv->proxy)572 if (priv->sticky)
571 {573 {
572 dbus_g_proxy_disconnect_signal (priv->proxy,574 bamf_view_unset_proxy (self);
573 "ActiveChanged",
574 (GCallback) bamf_view_on_active_changed,
575 self);
576
577 dbus_g_proxy_disconnect_signal (priv->proxy,
578 "Closed",
579 (GCallback) bamf_view_on_closed,
580 self);
581
582 dbus_g_proxy_disconnect_signal (priv->proxy,
583 "ChildAdded",
584 (GCallback) bamf_view_on_child_added,
585 self);
586
587 dbus_g_proxy_disconnect_signal (priv->proxy,
588 "ChildRemoved",
589 (GCallback) bamf_view_on_child_removed,
590 self);
591
592 dbus_g_proxy_disconnect_signal (priv->proxy,
593 "RunningChanged",
594 (GCallback) bamf_view_on_running_changed,
595 self);
596
597 dbus_g_proxy_disconnect_signal (priv->proxy,
598 "UrgentChanged",
599 (GCallback) bamf_view_on_urgent_changed,
600 self);
601
602 dbus_g_proxy_disconnect_signal (priv->proxy,
603 "UserVisibleChanged",
604 (GCallback) bamf_view_on_user_visible_changed,
605 self);
606
607 g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, self);
608 g_object_unref (priv->proxy);
609 priv->proxy = NULL;
610 }575 }
611 576
612 g_object_ref (self);577 g_object_ref (self);
@@ -668,6 +633,57 @@
668}633}
669634
670static void635static void
636bamf_view_unset_proxy (BamfView *self)
637{
638 BamfViewPrivate *priv;
639
640 g_return_if_fail (BAMF_IS_VIEW (self));
641 priv = self->priv;
642
643 if (!priv->proxy)
644 return;
645
646 dbus_g_proxy_disconnect_signal (priv->proxy,
647 "ActiveChanged",
648 (GCallback) bamf_view_on_active_changed,
649 self);
650
651 dbus_g_proxy_disconnect_signal (priv->proxy,
652 "Closed",
653 (GCallback) bamf_view_on_closed,
654 self);
655
656 dbus_g_proxy_disconnect_signal (priv->proxy,
657 "ChildAdded",
658 (GCallback) bamf_view_on_child_added,
659 self);
660
661 dbus_g_proxy_disconnect_signal (priv->proxy,
662 "ChildRemoved",
663 (GCallback) bamf_view_on_child_removed,
664 self);
665
666 dbus_g_proxy_disconnect_signal (priv->proxy,
667 "RunningChanged",
668 (GCallback) bamf_view_on_running_changed,
669 self);
670
671 dbus_g_proxy_disconnect_signal (priv->proxy,
672 "UrgentChanged",
673 (GCallback) bamf_view_on_urgent_changed,
674 self);
675
676 dbus_g_proxy_disconnect_signal (priv->proxy,
677 "UserVisibleChanged",
678 (GCallback) bamf_view_on_user_visible_changed,
679 self);
680
681 g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, self);
682 g_object_unref (priv->proxy);
683 priv->proxy = NULL;
684}
685
686static void
671bamf_view_dispose (GObject *object)687bamf_view_dispose (GObject *object)
672{688{
673 BamfView *view;689 BamfView *view;
@@ -688,7 +704,7 @@
688 g_free (priv->type);704 g_free (priv->type);
689 priv->type = NULL;705 priv->type = NULL;
690 }706 }
691707
692 if (priv->local_icon)708 if (priv->local_icon)
693 {709 {
694 g_free (priv->local_icon);710 g_free (priv->local_icon);
@@ -707,52 +723,7 @@
707 priv->cached_children = NULL;723 priv->cached_children = NULL;
708 }724 }
709725
710 if (priv->proxy)726 bamf_view_unset_proxy (view);
711 {
712 dbus_g_proxy_disconnect_signal (priv->proxy,
713 "ActiveChanged",
714 (GCallback) bamf_view_on_active_changed,
715 view);
716
717 dbus_g_proxy_disconnect_signal (priv->proxy,
718 "Closed",
719 (GCallback) bamf_view_on_closed,
720 view);
721
722 dbus_g_proxy_disconnect_signal (priv->proxy,
723 "ChildAdded",
724 (GCallback) bamf_view_on_child_added,
725 view);
726
727 dbus_g_proxy_disconnect_signal (priv->proxy,
728 "ChildRemoved",
729 (GCallback) bamf_view_on_child_removed,
730 view);
731
732 dbus_g_proxy_disconnect_signal (priv->proxy,
733 "RunningChanged",
734 (GCallback) bamf_view_on_running_changed,
735 view);
736
737 dbus_g_proxy_disconnect_signal (priv->proxy,
738 "UrgentChanged",
739 (GCallback) bamf_view_on_urgent_changed,
740 view);
741
742 dbus_g_proxy_disconnect_signal (priv->proxy,
743 "UserVisibleChanged",
744 (GCallback) bamf_view_on_user_visible_changed,
745 view);
746
747 dbus_g_proxy_disconnect_signal (priv->proxy,
748 "NameChanged",
749 (GCallback) bamf_view_on_name_changed,
750 view);
751
752 g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, view);
753 g_object_unref (priv->proxy);
754 priv->proxy = NULL;
755 }
756727
757 G_OBJECT_CLASS (bamf_view_parent_class)->dispose (object);728 G_OBJECT_CLASS (bamf_view_parent_class)->dispose (object);
758}729}
@@ -814,11 +785,7 @@
814 g_free (priv->path);785 g_free (priv->path);
815 }786 }
816787
817 if (priv->proxy)788 bamf_view_unset_proxy (view);
818 {
819 g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, view);
820 g_object_unref (priv->proxy);
821 }
822789
823 priv->path = g_strdup (path);790 priv->path = g_strdup (path);
824 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,791 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
825792
=== modified file 'lib/libbamf/bamf-window.c'
--- lib/libbamf/bamf-window.c 2012-04-26 17:11:45 +0000
+++ lib/libbamf/bamf-window.c 2012-05-17 06:00:25 +0000
@@ -228,6 +228,31 @@
228}228}
229229
230static void230static void
231bamf_window_unset_proxy (BamfWindow *self)
232{
233 BamfWindowPrivate *priv;
234
235 g_return_if_fail (BAMF_IS_WINDOW (self));
236 priv = self->priv;
237
238 if (!priv->proxy)
239 return;
240
241 dbus_g_proxy_disconnect_signal (self->priv->proxy,
242 "MaximizedChanged",
243 (GCallback) bamf_window_on_maximized_changed,
244 self);
245
246 dbus_g_proxy_disconnect_signal (self->priv->proxy,
247 "MonitorChanged",
248 (GCallback) bamf_window_on_monitor_changed,
249 self);
250
251 g_object_unref (priv->proxy);
252 priv->proxy = NULL;
253}
254
255static void
231bamf_window_set_path (BamfView *view, const char *path)256bamf_window_set_path (BamfView *view, const char *path)
232{257{
233 BamfWindow *self;258 BamfWindow *self;
@@ -236,6 +261,7 @@
236 self = BAMF_WINDOW (view);261 self = BAMF_WINDOW (view);
237 priv = self->priv;262 priv = self->priv;
238263
264 bamf_window_unset_proxy (self);
239 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,265 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
240 "org.ayatana.bamf",266 "org.ayatana.bamf",
241 path,267 path,
@@ -380,26 +406,9 @@
380bamf_window_dispose (GObject *object)406bamf_window_dispose (GObject *object)
381{407{
382 BamfWindow *self;408 BamfWindow *self;
383 BamfWindowPrivate *priv;
384 409
385 self = BAMF_WINDOW (object);410 self = BAMF_WINDOW (object);
386 priv = self->priv;411 bamf_window_unset_proxy (self);
387
388 if (priv->proxy)
389 {
390 dbus_g_proxy_disconnect_signal (priv->proxy,
391 "MaximizedChanged",
392 (GCallback) bamf_window_on_maximized_changed,
393 self);
394
395 dbus_g_proxy_disconnect_signal (priv->proxy,
396 "MonitorChanged",
397 (GCallback) bamf_window_on_monitor_changed,
398 self);
399
400 g_object_unref (priv->proxy);
401 priv->proxy = NULL;
402 }
403412
404 if (G_OBJECT_CLASS (bamf_window_parent_class)->dispose)413 if (G_OBJECT_CLASS (bamf_window_parent_class)->dispose)
405 G_OBJECT_CLASS (bamf_window_parent_class)->dispose (object);414 G_OBJECT_CLASS (bamf_window_parent_class)->dispose (object);
@@ -467,7 +476,7 @@
467{476{
468 BamfWindow *self;477 BamfWindow *self;
469 self = g_object_new (BAMF_TYPE_WINDOW, NULL);478 self = g_object_new (BAMF_TYPE_WINDOW, NULL);
470 479
471 bamf_view_set_path (BAMF_VIEW (self), path);480 bamf_view_set_path (BAMF_VIEW (self), path);
472481
473 return self;482 return self;

Subscribers

People subscribed via source and target branches