]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
liblib: If parent ostream closes itself on error, close our ostream as well.
authorTimo Sirainen <tss@iki.fi>
Fri, 11 Oct 2013 16:17:10 +0000 (19:17 +0300)
committerTimo Sirainen <tss@iki.fi>
Fri, 11 Oct 2013 16:17:10 +0000 (19:17 +0300)
This avoids a situation where ostream is basically unusable with
last_failed_errno set, but it's not marked as closed. The current code
often checks ostream->closed but doesn't check last_failed_errno.
ostream-file also autocloses the stream, but filter ostreams without this
patch don't autoclose, so this caused problems with e.g. IMAP COMPRESSION
extension where the zlib-ostream didn't get marked as closed, although the
problem was only logging "BUG: Unknown internal error" instead of
"Disconnected" as the client's disconnect reason.

src/lib/ostream.c

index d4a8c3b585c46a17a91f1418d1e2f8f5b5c99ec6..de58b2f1ad4e264034e582c3190c38c80d664a1b 100644 (file)
@@ -45,8 +45,10 @@ const char *o_stream_get_error(struct ostream *stream)
 
 static void o_stream_close_full(struct ostream *stream, bool close_parents)
 {
-       io_stream_close(&stream->real_stream->iostream, close_parents);
-       stream->closed = TRUE;
+       if (!stream->closed) {
+               io_stream_close(&stream->real_stream->iostream, close_parents);
+               stream->closed = TRUE;
+       }
 
        if (stream->stream_errno == 0)
                stream->stream_errno = EPIPE;
@@ -428,6 +430,8 @@ void o_stream_copy_error_from_parent(struct ostream_private *_stream)
        dest->stream_errno = src->stream_errno;
        dest->last_failed_errno = src->last_failed_errno;
        dest->overflow = src->overflow;
+       if (src->closed)
+               o_stream_close(dest);
 }
 
 static int o_stream_default_flush(struct ostream_private *_stream)