]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 12 Oct 2017 15:06:04 +0000 (18:06 +0300)
src/lib/iostream.c

index 321c4cf0c602fd553f4ff8fa1637c3c914316090..9cd12427655f6e5c4186199945df8649affd34f8 100644 (file)
@@ -105,8 +105,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,