From: Timo Sirainen Date: Fri, 11 Oct 2013 16:17:10 +0000 (+0300) Subject: liblib: If parent ostream closes itself on error, close our ostream as well. X-Git-Tag: 2.2.7~86 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d2ebe91d56e9a158de000c9d0026f65600fbcfa;p=thirdparty%2Fdovecot%2Fcore.git liblib: If parent ostream closes itself on error, close our ostream as well. 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. --- diff --git a/src/lib/ostream.c b/src/lib/ostream.c index d4a8c3b585..de58b2f1ad 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -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)