From 86b3b410b5f55cf010efd6f4fef65fc51de754e7 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Fri, 22 Nov 2019 19:51:15 +0100 Subject: [PATCH] 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. --- src/lib/ostream.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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) -- 2.47.3