changeset 22606:e154812ec781

lib: io_stream_set_error() - Allow one of the parameters to be the old error
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 09 Oct 2017 18:31:52 +0300
parents a9d5eebb326e
children 708b4dda62dc
files src/lib/iostream.c
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/iostream.c	Wed Oct 11 13:03:51 2017 +0300
+++ b/src/lib/iostream.c	Mon Oct 09 18:31:52 2017 +0300
@@ -105,8 +105,11 @@
 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,