From f0910b5cd80f62d9c5862aedbf62ee90374b2bca Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 9 Oct 2017 18:31:52 +0300 Subject: [PATCH] lib: io_stream_set_error() - Allow one of the parameters to be the old error --- src/lib/iostream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/iostream.c b/src/lib/iostream.c index cb7d9fa6e1..7d1762c491 100644 --- a/src/lib/iostream.c +++ b/src/lib/iostream.c @@ -110,8 +110,11 @@ void io_stream_set_error(struct iostream_private *stream, void io_stream_set_verror(struct iostream_private *stream, const char *fmt, va_list args) { + /* one of the parameters may be the old stream->error, so don't free + it before the new error is created. */ + char *error = i_strdup_vprintf(fmt, args); i_free(stream->error); - stream->error = i_strdup_vprintf(fmt, args); + stream->error = error; } const char *io_stream_get_disconnect_reason(struct istream *input, -- 2.47.3