aboutsummaryrefslogtreecommitdiff
path: root/src/core/aio.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-18 11:00:08 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-18 11:00:08 -0700
commitab7772be3e3c208a48408b67924d3b58fca7f474 (patch)
treeb7355183556350de73303c6e75a5d278528dda0e /src/core/aio.c
parentc41129ca0efacf13fe1363ed12f9723274c521e7 (diff)
downloadnng-ab7772be3e3c208a48408b67924d3b58fca7f474.tar.gz
nng-ab7772be3e3c208a48408b67924d3b58fca7f474.tar.bz2
nng-ab7772be3e3c208a48408b67924d3b58fca7f474.zip
Fix close-related leak of pipes.
We have seen leaks of pipes causing test failures (e.g. the Windows IPC test) due to EADDRINUSE. This was caused by a case where we failed to pass the pipe up because the AIO had already been canceled, and we didn't realize that we had oprhaned the pipe. The fix is to add a return value to nni_aio_finish, and verify that we did finish properly, or if we did not then we must free the pipe ourself. (The zero return from nni_aio_finish indicates that it accepts ownership of resources passed via the aio.)
Diffstat (limited to 'src/core/aio.c')
-rw-r--r--src/core/aio.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
index 73c1dd9b..c6512eb4 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -206,14 +206,14 @@ nni_aio_cancel(nni_aio *aio, int rv)
// I/O provider related functions.
-void
+int
nni_aio_finish(nni_aio *aio, int result, size_t count)
{
nni_mtx_lock(&aio->a_lk);
if (aio->a_flags & (NNI_AIO_DONE | NNI_AIO_FINI)) {
// Operation already done (canceled or timed out?)
nni_mtx_unlock(&aio->a_lk);
- return;
+ return (NNG_ESTATE);
}
aio->a_flags |= NNI_AIO_DONE;
aio->a_result = result;
@@ -228,6 +228,7 @@ nni_aio_finish(nni_aio *aio, int result, size_t count)
nni_taskq_dispatch(NULL, &aio->a_tqe);
nni_mtx_unlock(&aio->a_lk);
+ return (0);
}
void
@@ -307,7 +308,7 @@ nni_aio_expire_loop(void *arg)
nni_list *aios = &nni_aio_expire_aios;
nni_aio * aio;
nni_time now;
- int rv;
+
void (*cancelfn)(nni_aio *);
NNI_ARG_UNUSED(arg);