From: Timo Sirainen Date: Fri, 22 Nov 2013 11:47:36 +0000 (+0200) Subject: ostream: Don't mark the stream closed too early after all. X-Git-Tag: 2.2.9~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a48c2243fe98ca8393be7908f84d20c634bcdf9;p=thirdparty%2Fdovecot%2Fcore.git ostream: Don't mark the stream closed too early after all. Use another flag instead to avoid losing the last data written to the stream before closing. --- diff --git a/src/lib/ostream-private.h b/src/lib/ostream-private.h index 3edcaa36d5..5bbea990f3 100644 --- a/src/lib/ostream-private.h +++ b/src/lib/ostream-private.h @@ -37,6 +37,7 @@ struct ostream_private { void *context; unsigned int corked:1; + unsigned int closing:1; unsigned int last_errors_not_checked:1; unsigned int error_handling_disabled:1; }; diff --git a/src/lib/ostream.c b/src/lib/ostream.c index 73456aa66a..e22c86059c 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -45,9 +45,14 @@ const char *o_stream_get_error(struct ostream *stream) static void o_stream_close_full(struct ostream *stream, bool close_parents) { - if (!stream->closed) { - stream->closed = TRUE; + if (!stream->closed && !stream->real_stream->closing) { + /* first mark the stream as being closed so the + o_stream_copy_error_from_parent() won't recurse us back + here. but don't immediately mark the stream closed, because + we may still want to write something to it. */ + stream->real_stream->closing = TRUE; io_stream_close(&stream->real_stream->iostream, close_parents); + stream->closed = TRUE; } if (stream->stream_errno == 0)