]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: ostream - Use local variable for stream rather than pointer in o_stream_destroy().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 22 Nov 2019 18:51:15 +0000 (19:51 +0100)
committermartti.rannanjarvi <martti.rannanjarvi@open-xchange.com>
Sat, 18 Apr 2020 14:55:11 +0000 (14:55 +0000)
Problem is that a destroy callback can mess with the pointer, leading to all kinds of trouble.

src/lib/ostream.c

index b77ee278cc825169e590d30769455e3310a83e05..8c1394b9bd388ffa0870e8973d705eadc6259a17 100644 (file)
@@ -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)