[evolution] Avoid crashes when moving between messages quickly



commit f2c34011833c291568023f2a52a65f540f59671f
Author: Milan Crha <mcrha redhat com>
Date:   Wed Aug 3 16:59:22 2011 +0200

    Avoid crashes when moving between messages quickly
    
    The itip-formatter part is clean, but the one for attachment_button
    can still introduce runtime warnings, which requires more changes and
    rethinking of this all, which I prefer to postpone, the best after
    WebKit work will land, because it also may change most of the mail
    formatting code (I guess). It doesn't crash, at least.

 mail/em-format-html-display.c           |    2 ++
 mail/em-format-html.c                   |   12 +++++++++++-
 plugins/itip-formatter/itip-formatter.c |   20 +++++++++++++++++---
 3 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 90b60ac..d5e0353 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -978,10 +978,12 @@ efhd_attachment_button (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObj
 	e_attachment_set_can_show (attachment, info->handle != NULL);
 
 	web_view = em_format_html_get_web_view (efh);
+	g_return_val_if_fail (web_view != NULL, TRUE);
 	parent = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
 
 	view = em_format_html_display_get_attachment_view (efhd, info->attachment_view_part_id);
+	g_return_val_if_fail (view != NULL, TRUE);
 	gtk_widget_show (GTK_WIDGET (view));
 
 	store = e_attachment_view_get_store (view);
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index 4a34aa0..d79fa45 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -157,6 +157,7 @@ struct _format_msg {
 	CamelFolder *folder;
 	gchar *uid;
 	CamelMimeMessage *message;
+	gboolean cancelled;
 };
 
 static gchar *
@@ -177,8 +178,10 @@ efh_format_exec (struct _format_msg *m,
 	CamelURL *base;
 	gchar *content;
 
-	if (m->format->priv->web_view == NULL)
+	if (m->format->priv->web_view == NULL) {
+		m->cancelled = TRUE;
 		return;
+	}
 
 	format = EM_FORMAT (m->format);
 	stream = CAMEL_STREAM (m->estream);
@@ -265,6 +268,10 @@ efh_format_exec (struct _format_msg *m,
 				(CamelStream *) m->estream,
 				"</body>\n</html>\n", cancellable, NULL);
 			camel_stream_close ((CamelStream *) m->estream, cancellable, NULL);
+			if (g_cancellable_is_cancelled (cancellable)) {
+				m->cancelled = TRUE;
+				m->estream->sync.cancel = TRUE;
+			}
 			g_object_unref (m->estream);
 			m->estream = NULL;
 		}
@@ -274,6 +281,7 @@ efh_format_exec (struct _format_msg *m,
 	d(printf("out of jobs, done\n"));
 
 	format->pending_uri_level = puri_level;
+	m->cancelled = m->cancelled || g_cancellable_is_cancelled (cancellable);
 }
 
 static void
@@ -294,6 +302,8 @@ efh_format_free (struct _format_msg *m)
 	g_object_unref (m->format);
 	if (m->estream) {
 		camel_stream_close ((CamelStream *) m->estream, NULL, NULL);
+		if (m->cancelled)
+			m->estream->sync.cancel = TRUE;
 		g_object_unref (m->estream);
 	}
 	if (m->folder)
diff --git a/plugins/itip-formatter/itip-formatter.c b/plugins/itip-formatter/itip-formatter.c
index 46b7abb..82bc373 100644
--- a/plugins/itip-formatter/itip-formatter.c
+++ b/plugins/itip-formatter/itip-formatter.c
@@ -803,8 +803,9 @@ get_object_without_rid_ready_cb (GObject *source_object, GAsyncResult *result, g
 		icalcomp = NULL;
 
 	if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
-	    g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		g_error_free (error);
+	    g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+	    g_cancellable_is_cancelled (fd->cancellable)) {
+		g_clear_error (&error);
 		find_cal_update_ui (fd, cal_client);
 		decrease_find_data (fd);
 		return;
@@ -843,7 +844,8 @@ get_object_with_rid_ready_cb (GObject *source_object, GAsyncResult *result, gpoi
 		icalcomp = NULL;
 
 	if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
-	    g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	    g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) ||
+	    g_cancellable_is_cancelled (fd->cancellable)) {
 		g_error_free (error);
 		find_cal_update_ui (fd, cal_client);
 		decrease_find_data (fd);
@@ -887,6 +889,12 @@ get_object_list_ready_cb (GObject *source_object, GAsyncResult *result, gpointer
 	if (!e_cal_client_get_object_list_finish (cal_client, result, &objects, &error))
 		objects = NULL;
 
+	if (g_cancellable_is_cancelled (fd->cancellable)) {
+		g_clear_error (&error);
+		decrease_find_data (fd);
+		return;
+	}
+
 	if (error) {
 		if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
 		    g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
@@ -926,6 +934,12 @@ find_cal_opened_cb (GObject *source_object, GAsyncResult *result, gpointer user_
 		}
 	}
 
+	if (g_cancellable_is_cancelled (fd->cancellable)) {
+		g_clear_error (&error);
+		decrease_find_data (fd);
+		return;
+	}
+
 	if (error) {
 		/* FIXME Do we really want to warn here?  If we fail
 		 * to find the item, this won't be cleared but the



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]