changeset 7024:b42691420ff8 HEAD

Assert-crash if mail's input stream is closed too early or too late.
author Timo Sirainen <tss@iki.fi>
date Sat, 22 Dec 2007 02:56:01 +0200
parents 56a5a00e490c
children 984c05510dbc
files src/lib-storage/index/index-mail.c src/lib-storage/index/index-mail.h
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-mail.c	Sat Dec 22 02:54:58 2007 +0200
+++ b/src/lib-storage/index/index-mail.c	Sat Dec 22 02:56:01 2007 +0200
@@ -754,6 +754,13 @@
 	return ret;
 }
 
+static void index_mail_stream_destroy_callback(struct index_mail *mail)
+{
+	i_assert(mail->data.destroying_stream);
+
+	mail->data.destroying_stream = FALSE;
+}
+
 int index_mail_init_stream(struct index_mail *mail,
 			   struct message_size *hdr_size,
 			   struct message_size *body_size,
@@ -761,6 +768,9 @@
 {
 	struct index_mail_data *data = &mail->data;
 
+	i_stream_set_destroy_callback(data->stream,
+				      index_mail_stream_destroy_callback, mail);
+
 	if (hdr_size != NULL || body_size != NULL)
 		(void)get_cached_msgpart_sizes(mail);
 
@@ -1024,8 +1034,11 @@
 
 	if (mail->data.parser_ctx != NULL)
 		(void)message_parser_deinit(&mail->data.parser_ctx);
-	if (mail->data.stream != NULL)
+	if (mail->data.stream != NULL) {
+		mail->data.destroying_stream = TRUE;
 		i_stream_unref(&mail->data.stream);
+		i_assert(!mail->data.destroying_stream);
+	}
 	if (mail->data.filter_stream != NULL)
 		i_stream_unref(&mail->data.filter_stream);
 }
--- a/src/lib-storage/index/index-mail.h	Sat Dec 22 02:54:58 2007 +0200
+++ b/src/lib-storage/index/index-mail.h	Sat Dec 22 02:56:01 2007 +0200
@@ -103,6 +103,7 @@
 	unsigned int body_size_set:1;
 	unsigned int messageparts_saved_to_cache:1;
 	unsigned int header_parsed:1;
+	unsigned int destroying_stream:1;
 };
 
 struct index_mail {