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);
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))