changeset 19538:dfee8dea71b6

imap: Avoid crashing at deinit if mail_user_unref() triggers mail_storage_callbacks This could have happened with Maildir/mbox and autoexpunging.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 04 Jan 2016 14:34:01 -0500
parents 304b06f6302c
children 504104af673f
files src/imap/imap-client.c
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-client.c	Mon Jan 04 14:23:46 2016 -0500
+++ b/src/imap/imap-client.c	Mon Jan 04 14:34:01 2016 -0500
@@ -385,9 +385,7 @@
 		timeout_remove(&client->to_delayed_input);
 	timeout_remove(&client->to_idle);
 
-	i_stream_destroy(&client->input);
-	o_stream_destroy(&client->output);
-
+	/* i/ostreams are already closed at this stage, so fd can be closed */
 	net_disconnect(client->fd_in);
 	if (client->fd_in != client->fd_out)
 		net_disconnect(client->fd_out);
@@ -396,6 +394,11 @@
 	   some background work like autoexpunging. */
 	mail_user_unref(&client->user);
 
+	/* free the i/ostreams after mail_user_unref(), which could trigger
+	   mail_storage_callbacks notifications that write to the ostream. */
+	i_stream_destroy(&client->input);
+	o_stream_destroy(&client->output);
+
 	if (array_is_created(&client->search_saved_uidset))
 		array_free(&client->search_saved_uidset);
 	if (array_is_created(&client->search_updates))