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