aboutsummaryrefslogtreecommitdiff
path: root/src/core/init.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-21 17:40:04 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-21 17:40:04 -0800
commit568a84ed2d3d41da5ca64cde15a677237fffd991 (patch)
tree92ee212c0c8f4dc264acd0cef33285bddefd5a93 /src/core/init.c
parent434cdd9f4e9211b99ba62ff6973e082b90e098f0 (diff)
downloadnng-568a84ed2d3d41da5ca64cde15a677237fffd991.tar.gz
nng-568a84ed2d3d41da5ca64cde15a677237fffd991.tar.bz2
nng-568a84ed2d3d41da5ca64cde15a677237fffd991.zip
Fix leaks in bus, socket leaks, tighten up close-side refcnting.
This does a few things. First it closes some preexisting leaks. Second it tightens the overall close logic so that we automatically discard idhash resources (while keeping numeric values for next id etc. around) when the last socket is closed. This then eliminates the need for applications to ever explicitly terminate resources. It turns out platform-specific resources established at nni_init() time might still be leaked, but it's also the case that we now no longer dynamically allocate anything at platform initialization time. (This presumes that the platform doesn't do so under the hood when creating critical sections or mutexes for example.)
Diffstat (limited to 'src/core/init.c')
-rw-r--r--src/core/init.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/core/init.c b/src/core/init.c
index 48a5096c..8ada0247 100644
--- a/src/core/init.c
+++ b/src/core/init.c
@@ -15,6 +15,10 @@ nni_idhash *nni_endpoints;
nni_idhash *nni_pipes;
nni_idhash *nni_sockets;
nni_mtx *nni_idlock;
+
+static nni_idhash nni_endpoints_x;
+static nni_idhash nni_pipes_x;
+static nni_idhash nni_sockets_x;
static nni_mtx nni_idlock_x;
static int
@@ -28,17 +32,23 @@ nni_init_helper(void)
if ((rv = nni_mtx_init(&nni_idlock_x)) != 0) {
return (rv);
}
- if (((rv = nni_idhash_create(&nni_endpoints)) != 0) ||
- ((rv = nni_idhash_create(&nni_pipes)) != 0) ||
- ((rv = nni_idhash_create(&nni_sockets)) != 0)) {
+ if (((rv = nni_idhash_init(&nni_endpoints_x)) != 0) ||
+ ((rv = nni_idhash_init(&nni_pipes_x)) != 0) ||
+ ((rv = nni_idhash_init(&nni_sockets_x)) != 0)) {
nni_mtx_fini(&nni_idlock_x);
nni_random_fini();
return (rv);
}
- nni_idhash_set_limits(nni_pipes, 1, 0x7fffffff,
+ nni_idhash_set_limits(&nni_pipes_x, 1, 0x7fffffff,
nni_random() & 0x7fffffff);
- nni_idhash_set_limits(nni_sockets, 1, 0xffffffff, 1);
+ nni_idhash_set_limits(&nni_sockets_x, 1, 0x7fffffff, 1);
+ nni_idhash_set_limits(&nni_endpoints_x, 1, 0xffffffff, 1);
+
nni_idlock = &nni_idlock_x;
+ nni_pipes = &nni_pipes_x;
+ nni_endpoints = &nni_endpoints_x;
+ nni_sockets = &nni_sockets_x;
+
nni_tran_init();
return (0);
}
@@ -54,9 +64,9 @@ nni_init(void)
void
nni_fini(void)
{
- nni_idhash_destroy(nni_endpoints);
- nni_idhash_destroy(nni_pipes);
- nni_idhash_destroy(nni_sockets);
+ nni_idhash_fini(&nni_endpoints_x);
+ nni_idhash_fini(&nni_pipes_x);
+ nni_idhash_fini(&nni_sockets_x);
nni_mtx_fini(&nni_idlock_x);
nni_tran_fini();
nni_random_fini();