From a1bfa3de91d6fa6134e2d13777ccec2ddf73d1fc Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 18 Jan 2017 11:26:12 -0800 Subject: Reaper exits too soon, leaking bits. --- src/core/socket.c | 4 +++- src/core/socket.h | 1 + src/platform/posix/posix_rand.c | 1 + tests/pipeline.c | 6 +++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/socket.c b/src/core/socket.c index 1b4d1585..0ae20a28 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -77,7 +77,7 @@ nni_reaper(void *arg) continue; } - if ((sock->s_closing) && + if ((sock->s_reapexit) && (nni_list_first(&sock->s_reaps) == NULL) && (nni_list_first(&sock->s_pipes) == NULL)) { nni_mtx_unlock(&sock->s_mx); @@ -198,6 +198,7 @@ nni_sock_open(nni_sock **sockp, uint16_t pnum) sock->s_closing = 0; sock->s_reconn = NNI_SECOND; sock->s_reconnmax = NNI_SECOND; + sock->s_reapexit = 0; NNI_LIST_INIT(&sock->s_pipes, nni_pipe, p_node); NNI_LIST_INIT(&sock->s_reaps, nni_pipe, p_node); NNI_LIST_INIT(&sock->s_eps, nni_ep, ep_node); @@ -382,6 +383,7 @@ nni_sock_shutdown(nni_sock *sock) sock->s_sock_ops.sock_close(sock->s_data); + sock->s_reapexit = 1; nni_cv_wake(&sock->s_notify_cv); nni_cv_wake(&sock->s_cv); nni_mtx_unlock(&sock->s_mx); diff --git a/src/core/socket.h b/src/core/socket.h index 424b1321..1743869a 100644 --- a/src/core/socket.h +++ b/src/core/socket.h @@ -49,6 +49,7 @@ struct nng_socket { int s_ep_pend; // EP dial/listen in progress int s_closing; // Socket is closing + int s_reapexit; // Shutdown the reaper int s_besteffort; // Best effort mode delivery int s_senderr; // Protocol state machine use int s_recverr; // Protocol state machine use diff --git a/src/platform/posix/posix_rand.c b/src/platform/posix/posix_rand.c index f8986e07..11d166bd 100644 --- a/src/platform/posix/posix_rand.c +++ b/src/platform/posix/posix_rand.c @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef NNG_USE_GETRANDOM #include diff --git a/tests/pipeline.c b/tests/pipeline.c index a01409c4..5339146f 100644 --- a/tests/pipeline.c +++ b/tests/pipeline.c @@ -66,9 +66,9 @@ Main({ }) Convey("We can create a linked PUSH/PULL pair", { - nng_socket *push; - nng_socket *pull; - nng_socket *what; + nng_socket *push = NULL; + nng_socket *pull = NULL; + nng_socket *what = NULL; So(nng_open(&push, NNG_PROTO_PUSH) == 0); So(nng_open(&pull, NNG_PROTO_PULL) == 0); -- cgit v1.2.3-70-g09d2