From 25ec868bd8b5375e1c1c4c3331d761667ddfe26c Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 18 May 2016 17:42:06 +0300 Subject: [PATCH] lib: iostream-temp: Fixed sending more output after o_stream_send_istream() --- src/lib/iostream-temp.c | 6 ++++++ src/lib/test-iostream-temp.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/lib/iostream-temp.c b/src/lib/iostream-temp.c index f3776c6af8..779c4481c4 100644 --- a/src/lib/iostream-temp.c +++ b/src/lib/iostream-temp.c @@ -30,6 +30,8 @@ struct temp_ostream { uoff_t fd_size; }; +static int o_stream_temp_dup_cancel(struct temp_ostream *tstream); + static void o_stream_temp_close(struct iostream_private *stream, bool close_parent ATTR_UNUSED) @@ -104,6 +106,10 @@ o_stream_temp_sendv(struct ostream_private *stream, unsigned int i; tstream->flags &= ~IOSTREAM_TEMP_FLAG_TRY_FD_DUP; + if (tstream->dupstream != NULL) { + if (o_stream_temp_dup_cancel(tstream) < 0) + return -1; + } if (tstream->fd != -1) return o_stream_temp_fd_sendv(tstream, iov, iov_count); diff --git a/src/lib/test-iostream-temp.c b/src/lib/test-iostream-temp.c index d2978a6e24..d4157ba3c5 100644 --- a/src/lib/test-iostream-temp.c +++ b/src/lib/test-iostream-temp.c @@ -76,6 +76,16 @@ static void test_iostream_temp_istream(void) test_expect_no_more_errors(); o_stream_destroy(&output); + /* non-working fd-dup: write data after sending istream */ + i_stream_seek(input, 0); + output = iostream_temp_create_sized(".intentional-nonexistent-error/", + IOSTREAM_TEMP_FLAG_TRY_FD_DUP, "test", 4); + test_assert(o_stream_send_istream(output, input) > 0); + test_expect_errors(1); + test_assert(o_stream_send(output, "1", 1) == 1); + test_expect_no_more_errors(); + o_stream_destroy(&output); + /* non-working fd-dup: send two istreams */ i_stream_seek(input, 0); input2 = i_stream_create_limit(input, (uoff_t)-1);