aboutsummaryrefslogtreecommitdiff
path: root/src/core/aio.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-06-12 10:34:22 -0700
committerGarrett D'Amore <garrett@damore.org>2018-06-12 10:34:22 -0700
commitaaec633023a1b3f2c6d24fe697bda4737abe84ee (patch)
tree9907fd916d61e82abd300425670bddeb417788ad /src/core/aio.c
parent79c761b66276289ebe703b596e285469deaa7a16 (diff)
downloadnng-aaec633023a1b3f2c6d24fe697bda4737abe84ee.tar.gz
nng-aaec633023a1b3f2c6d24fe697bda4737abe84ee.tar.bz2
nng-aaec633023a1b3f2c6d24fe697bda4737abe84ee.zip
fixes #533 nni_aio_begin should not dispatch task on NNG_ECLOSED.
This changes nni_aio_begin so that it immediately terminates when it encounters aio->a_closed, much like it does for aio->a_stop. The semantic for nni_aio_close() is supposed to be like nni_aio_stop(), but without blocking. I suspect that this might be responsible for use-after-free bugs that seem to have been rearing their head lately.
Diffstat (limited to 'src/core/aio.c')
-rw-r--r--src/core/aio.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
index 87755b1b..fc7a7960 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -337,6 +337,11 @@ nni_aio_begin(nni_aio *aio)
nni_mtx_unlock(&nni_aio_lk);
return (NNG_ECANCELED);
}
+ if (aio->a_closed) {
+ aio->a_result = NNG_ECLOSED;
+ nni_mtx_unlock(&nni_aio_lk);
+ return (NNG_ECLOSED);
+ }
aio->a_result = 0;
aio->a_count = 0;
aio->a_prov_cancel = NULL;
@@ -345,14 +350,6 @@ nni_aio_begin(nni_aio *aio)
aio->a_outputs[i] = NULL;
}
nni_task_prep(aio->a_task);
- if (aio->a_closed) {
- aio->a_result = NNG_ECLOSED;
- aio->a_expire = NNI_TIME_NEVER;
- aio->a_sleep = false;
- nni_mtx_unlock(&nni_aio_lk);
- nni_task_dispatch(aio->a_task);
- return (NNG_ECLOSED);
- }
nni_mtx_unlock(&nni_aio_lk);
return (0);
}