From: Stephan Bosch Date: Fri, 22 Nov 2019 18:51:15 +0000 (+0100) Subject: lib: ostream - Use local variable for stream rather than pointer in o_stream_destroy(). X-Git-Tag: 2.3.11.2~309 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=86b3b410b5f55cf010efd6f4fef65fc51de754e7;p=thirdparty%2Fdovecot%2Fcore.git lib: ostream - Use local variable for stream rather than pointer in o_stream_destroy(). Problem is that a destroy callback can mess with the pointer, leading to all kinds of trouble. --- diff --git a/src/lib/ostream.c b/src/lib/ostream.c index b77ee278cc..8c1394b9bd 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -67,13 +67,16 @@ static void o_stream_close_full(struct ostream *stream, bool close_parents) stream->stream_errno = EPIPE; } -void o_stream_destroy(struct ostream **stream) +void o_stream_destroy(struct ostream **_stream) { - if (*stream == NULL) + struct ostream *stream = *_stream; + + if (stream == NULL) return; - o_stream_close_full(*stream, FALSE); - o_stream_unref(stream); + *_stream = NULL; + o_stream_close_full(stream, FALSE); + o_stream_unref(&stream); } void o_stream_ref(struct ostream *stream)