From 81f5d3c6268ff91ee9c36c4cb34f6f9bfd54740d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 12 Dec 2024 17:55:48 -0800 Subject: streams: add explicit stop functions This allows us to explicitly stop streams, dialers, and listeners, before we start tearing down things. This hopefully will be useful in resolving use-after-free bugs in http, tls, and websockets. The new functions are not yet documented, but they are nng_stream_stop, nng_stream_dialer_stop, and nng_stream_listener_stop. They should be called after close, and before free. The close functions now close without blocking, but the stop function is allowed to block. --- src/core/stream.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/core/stream.c') diff --git a/src/core/stream.c b/src/core/stream.c index ad026586..16e11eca 100644 --- a/src/core/stream.c +++ b/src/core/stream.c @@ -116,7 +116,17 @@ static struct { void nng_stream_close(nng_stream *s) { - s->s_close(s); + if (s != NULL) { + s->s_close(s); + } +} + +void +nng_stream_stop(nng_stream *s) +{ + if (s != NULL) { + s->s_stop(s); + } } void @@ -149,7 +159,17 @@ nni_stream_get( void nng_stream_dialer_close(nng_stream_dialer *d) { - d->sd_close(d); + if (d != NULL) { + d->sd_close(d); + } +} + +void +nng_stream_dialer_stop(nng_stream_dialer *d) +{ + if (d != NULL) { + d->sd_stop(d); + } } void @@ -226,8 +246,19 @@ nni_stream_dialer_set_tls(nng_stream_dialer *d, nng_tls_config *cfg) void nng_stream_listener_close(nng_stream_listener *l) { - l->sl_close(l); + if (l != NULL) { + l->sl_close(l); + } +} + +void +nng_stream_listener_stop(nng_stream_listener *l) +{ + if (l != NULL) { + l->sl_stop(l); + } } + void nng_stream_listener_free(nng_stream_listener *l) { -- cgit v1.2.3-70-g09d2