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/supplemental/websocket/websocket_test.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/supplemental/websocket/websocket_test.c') diff --git a/src/supplemental/websocket/websocket_test.c b/src/supplemental/websocket/websocket_test.c index 781ca1d8..9a28d69b 100644 --- a/src/supplemental/websocket/websocket_test.c +++ b/src/supplemental/websocket/websocket_test.c @@ -107,9 +107,13 @@ test_websocket_wildcard(void) NUTS_TRUE(memcmp(buf1, buf2, 5) == 0); nng_stream_close(c1); - nng_stream_free(c1); nng_stream_close(c2); + nng_stream_stop(c1); + nng_stream_stop(c2); + nng_stream_free(c1); nng_stream_free(c2); + nng_stream_listener_stop(l); + nng_stream_dialer_stop(d); nng_aio_free(daio); nng_aio_free(laio); nng_aio_free(aio1); @@ -206,9 +210,13 @@ test_websocket_conn_props(void) nng_strfree(str); nng_stream_close(c1); - nng_stream_free(c1); nng_stream_close(c2); + nng_stream_stop(c1); + nng_stream_stop(c2); + nng_stream_free(c1); nng_stream_free(c2); + nng_stream_listener_stop(l); + nng_stream_dialer_stop(d); nng_aio_free(daio); nng_aio_free(laio); nng_stream_listener_free(l); @@ -495,6 +503,7 @@ test_websocket_fragmentation(void) nng_aio_free(caio); nng_stream_close(c); + nng_stream_stop(c); nng_stream_free(c); nng_aio_free(state.aio); @@ -502,6 +511,8 @@ test_websocket_fragmentation(void) nng_cv_free(state.cv); nng_mtx_free(state.lock); + nng_stream_dialer_stop(d); + nng_stream_listener_stop(l); nng_free(send_buf, state.total); nng_free(recv_buf, state.total); nng_aio_free(daio); -- cgit v1.2.3-70-g09d2