]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: io_stream_set_error() - Allow one of the parameters to be the old error
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 9 Oct 2017 15:31:52 +0000 (18:31 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Wed, 11 Oct 2017 09:17:42 +0000 (12:17 +0300)
src/lib/iostream.c

index cb7d9fa6e19556e41a5d20bbd5219f8c72891efa..7d1762c491a31b53bb2d6a596bf96296ed4019c3 100644 (file)
@@ -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,