From 54384b72172d92bb69d136b564a6096978f50695 Mon Sep 17 00:00:00 2001
From: Matthew Barnes <mbarnes@redhat.com>
Date: Mon, 10 Jun 2013 16:37:03 -0400
Subject: ECalShellView: Disconnect "prepare-for-quit" handler on dispose().

This is another source of crashes after creating and destroying a second
shell window.  The signal handler was left connected with the destroyed
shell window as the closure.
---
 modules/calendar/e-cal-shell-view-private.c | 8 ++++++++
 modules/calendar/e-cal-shell-view-private.h | 3 +++
 modules/calendar/e-cal-shell-view.c         | 6 +++++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c
index 99de61c4ee..8f5ce93792 100644
--- a/modules/calendar/e-cal-shell-view-private.c
+++ b/modules/calendar/e-cal-shell-view-private.c
@@ -734,6 +734,13 @@ e_cal_shell_view_private_dispose (ECalShellView *cal_shell_view)
 	if (priv->cal_shell_content != NULL)
 		e_cal_shell_content_save_state (priv->cal_shell_content);
 
+	if (priv->prepare_for_quit_handler_id > 0) {
+		g_signal_handler_disconnect (
+			priv->shell,
+			priv->prepare_for_quit_handler_id);
+		priv->prepare_for_quit_handler_id = 0;
+	}
+
 	if (priv->backend_error_handler_id > 0) {
 		g_signal_handler_disconnect (
 			priv->client_cache,
@@ -745,6 +752,7 @@ e_cal_shell_view_private_dispose (ECalShellView *cal_shell_view)
 	g_clear_object (&priv->cal_shell_content);
 	g_clear_object (&priv->cal_shell_sidebar);
 
+	g_clear_object (&priv->shell);
 	g_clear_object (&priv->client_cache);
 
 	if (priv->calendar_activity != NULL) {
diff --git a/modules/calendar/e-cal-shell-view-private.h b/modules/calendar/e-cal-shell-view-private.h
index 7931eb3a3d..30962d841b 100644
--- a/modules/calendar/e-cal-shell-view-private.h
+++ b/modules/calendar/e-cal-shell-view-private.h
@@ -93,6 +93,9 @@ struct _ECalShellViewPrivate {
 	ECalShellContent *cal_shell_content;
 	ECalShellSidebar *cal_shell_sidebar;
 
+	EShell *shell;
+	gulong prepare_for_quit_handler_id;
+
 	EClientCache *client_cache;
 	gulong backend_error_handler_id;
 
diff --git a/modules/calendar/e-cal-shell-view.c b/modules/calendar/e-cal-shell-view.c
index a6e347528d..39f1472dbb 100644
--- a/modules/calendar/e-cal-shell-view.c
+++ b/modules/calendar/e-cal-shell-view.c
@@ -101,6 +101,7 @@ cal_shell_view_constructed (GObject *object)
 	ECalShellContent *cal_shell_content;
 	GtkWidget *container;
 	GtkWidget *widget;
+	gulong handler_id;
 
 	/* Chain up to parent's constructed() method. */
 	G_OBJECT_CLASS (parent_class)->constructed (object);
@@ -126,10 +127,13 @@ cal_shell_view_constructed (GObject *object)
 	gtk_container_add (GTK_CONTAINER (container), widget);
 	gtk_widget_show (widget);
 
-	g_signal_connect (
+	handler_id = g_signal_connect (
 		shell, "prepare-for-quit",
 		G_CALLBACK (cal_shell_view_prepare_for_quit_cb),
 		cal_shell_view);
+
+	cal_shell_view->priv->shell = g_object_ref (shell);
+	cal_shell_view->priv->prepare_for_quit_handler_id = handler_id;
 }
 
 static void
-- 
cgit v1.2.3