]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
ostream: Don't mark the stream closed too early after all.
authorTimo Sirainen <tss@iki.fi>
Fri, 22 Nov 2013 11:47:36 +0000 (13:47 +0200)
committerTimo Sirainen <tss@iki.fi>
Fri, 22 Nov 2013 11:47:36 +0000 (13:47 +0200)
Use another flag instead to avoid losing the last data written to the stream
before closing.

src/lib/ostream-private.h
src/lib/ostream.c

index 3edcaa36d5c74df90564c53bd1e35cc192aaf268..5bbea990f3e8f2cc27dac119c2e92935e38bd094 100644 (file)
@@ -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;
 };
index 73456aa66a254d47a1633fcdd24fed8f9eeab76c..e22c86059c8af9485c01f5d1bb5a5af35bada4bd 100644 (file)
@@ -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)