aboutsummaryrefslogtreecommitdiff
path: root/src/sp
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-26 14:32:34 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-26 15:57:48 -0800
commitc8b58f9128dd1e4b9424d79d22f5ae50a8bff54a (patch)
tree73d1d368a67cce45eec797704f85d9e3545ef93b /src/sp
parent1ad7f88e0c58285c9e1cad9448d5a1fcfa7a07f1 (diff)
downloadnng-c8b58f9128dd1e4b9424d79d22f5ae50a8bff54a.tar.gz
nng-c8b58f9128dd1e4b9424d79d22f5ae50a8bff54a.tar.bz2
nng-c8b58f9128dd1e4b9424d79d22f5ae50a8bff54a.zip
udp: use nni_aio_start
This also moves the close of the UDP socket later, to avoid a potential use after free while the aio's are still in-flight. Unfortunately we cannot unbind cleanly without a hard close.
Diffstat (limited to 'src/sp')
-rw-r--r--src/sp/transport/udp/udp.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/sp/transport/udp/udp.c b/src/sp/transport/udp/udp.c
index 97ffdc04..f2fc6889 100644
--- a/src/sp/transport/udp/udp.c
+++ b/src/sp/transport/udp/udp.c
@@ -1108,6 +1108,10 @@ udp_ep_fini(void *arg)
nni_aio_fini(&ep->tx_aio);
nni_aio_fini(&ep->rx_aio);
+ if (ep->udp != NULL) {
+ nni_udp_close(ep->udp);
+ }
+
for (int i = 0; i < ep->tx_ring.size; i++) {
nni_msg_free(ep->tx_ring.descs[i].payload);
ep->tx_ring.descs[i].payload = NULL;
@@ -1167,10 +1171,6 @@ udp_ep_stop(void *arg)
// finally close the tx channel
nni_aio_stop(&ep->tx_aio);
-
- if (ep->udp != NULL) {
- nni_udp_close(ep->udp);
- }
}
// timer handler - sends out additional creqs as needed,
@@ -1517,12 +1517,12 @@ static void
udp_ep_connect(void *arg, nni_aio *aio)
{
udp_ep *ep = arg;
- int rv;
- if (nni_aio_begin(aio) != 0) {
+ nni_mtx_lock(&ep->mtx);
+ if (!nni_aio_start(aio, udp_ep_cancel, ep)) {
+ nni_mtx_unlock(&ep->mtx);
return;
}
- nni_mtx_lock(&ep->mtx);
if (ep->closed) {
nni_mtx_unlock(&ep->mtx);
nni_aio_finish_error(aio, NNG_ECLOSED);
@@ -1536,12 +1536,6 @@ udp_ep_connect(void *arg, nni_aio *aio)
NNI_ASSERT(nni_list_empty(&ep->connaios));
ep->dialer = true;
- if ((rv = nni_aio_schedule(aio, udp_ep_cancel, ep)) != 0) {
- nni_mtx_unlock(&ep->mtx);
- nni_aio_finish_error(aio, rv);
- return;
- }
-
nni_list_append(&ep->connaios, aio);
// lookup the IP address