From ee4572147ade37bf07f8ef2f3049e8c81df312b7 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 11 Aug 2017 17:51:41 -0700 Subject: Fix leaks found in pairv1 test suite. --- src/protocol/pair/pair_v1.c | 10 +++++----- tests/pair1.c | 12 ++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/protocol/pair/pair_v1.c b/src/protocol/pair/pair_v1.c index 183c260a..1a7ad9fa 100644 --- a/src/protocol/pair/pair_v1.c +++ b/src/protocol/pair/pair_v1.c @@ -177,16 +177,16 @@ pair1_pipe_stop(void *arg) pair1_pipe *p = arg; pair1_sock *s = p->psock; + nni_mtx_lock(&s->mtx); + nni_idhash_remove(s->pipes, nni_pipe_id(p->npipe)); + nni_list_node_remove(&p->node); + nni_mtx_unlock(&s->mtx); + nni_msgq_close(p->sendq); nni_aio_cancel(&p->aio_send, NNG_ECANCELED); nni_aio_cancel(&p->aio_recv, NNG_ECANCELED); nni_aio_cancel(&p->aio_putq, NNG_ECANCELED); nni_aio_cancel(&p->aio_getq, NNG_ECANCELED); - - nni_mtx_lock(&s->mtx); - nni_idhash_remove(s->pipes, nni_pipe_id(p->npipe)); - nni_list_node_remove(&p->node); - nni_mtx_unlock(&s->mtx); } static void diff --git a/tests/pair1.c b/tests/pair1.c index b9ef9f03..da5eaa24 100644 --- a/tests/pair1.c +++ b/tests/pair1.c @@ -34,6 +34,7 @@ TestMain("PAIRv1 protocol", { nng_close(s1); nng_close(c1); nng_close(c2); + nng_usleep(10000); nni_fini(); }); @@ -119,7 +120,7 @@ TestMain("PAIRv1 protocol", { So(nng_setopt(s1, NNG_OPT_RCVBUF, &r, sizeof(r)) == 0); So(nng_setopt(s1, NNG_OPT_SNDBUF, &r, sizeof(r)) == 0); So(nng_setopt(c1, NNG_OPT_RCVBUF, &r, sizeof(r)) == 0); - tmo = 10000; + tmo = 100000; So(nng_setopt( s1, NNG_OPT_SNDTIMEO, &tmo, sizeof(tmo)) == 0); @@ -129,6 +130,7 @@ TestMain("PAIRv1 protocol", { for (i = 0, rv = 0; i < 10; i++) { So(nng_msg_alloc(&msg, 0) == 0); if ((rv = nng_sendmsg(s1, msg, 0)) != 0) { + nni_msg_free(msg); break; } } @@ -146,7 +148,7 @@ TestMain("PAIRv1 protocol", { So(nng_setopt(s1, NNG_OPT_SNDBUF, &r, sizeof(r)) == 0); So(nng_setopt(c1, NNG_OPT_RCVBUF, &r, sizeof(r)) == 0); - tmo = 10000; + tmo = 30000; So(nng_setopt( s1, NNG_OPT_SNDTIMEO, &tmo, sizeof(tmo)) == 0); @@ -232,6 +234,7 @@ TestMain("PAIRv1 protocol", { So(nng_recvmsg(s1, &msg, 0) == 0); So(nng_msg_trim_u32(msg, &v) == 0); So(v == 0xFEEDFACE); + nng_msg_free(msg); }); Convey("Reserved bits in raw header", { @@ -254,6 +257,7 @@ TestMain("PAIRv1 protocol", { So(nng_recvmsg(s1, &msg, 0) == 0); So(nng_msg_trim_u32(msg, &v) == 0); So(v == 0xFEEDFACE); + nng_msg_free(msg); }); }); @@ -288,7 +292,9 @@ TestMain("PAIRv1 protocol", { So(nng_msg_header_trim_u32(msg, &v) == 0); So(v == 4); + nng_msg_free(msg); }); + Convey("Large TTL passes", { ttl = 0xff; So(nng_setopt(s1, NNG_OPT_MAXTTL, &ttl, @@ -304,7 +310,9 @@ TestMain("PAIRv1 protocol", { So(nng_msg_header_trim_u32(msg, &v) == 0); So(v == 0xff); + nng_msg_free(msg); }); + Convey("Max TTL fails", { ttl = 0xff; So(nng_setopt(s1, NNG_OPT_MAXTTL, &ttl, -- cgit v1.2.3-70-g09d2