From 83049ceabf14679583dbfa7d5ee84587db8a0463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Kr=C4=99cicki?= Date: Wed, 29 Apr 2020 15:19:32 +0200 Subject: [PATCH] Don't free udp recv buffer if UV_UDP_MMSG_CHUNK is set --- lib/isc/netmgr/netmgr.c | 2 +- lib/isc/netmgr/udp.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 180d3336f9..66ddeb8e9c 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -996,7 +996,7 @@ isc__nm_free_uvbuf(isc_nmsocket_t *sock, const uv_buf_t *buf) { if (buf->base > worker->recvbuf && buf->base <= worker->recvbuf + ISC_NETMGR_RECVBUF_SIZE) { - /* Can happen in case of recvmmsg */ + /* Can happen in case of out-of-order recvmmsg in libuv1.36 */ return; } REQUIRE(buf->base == worker->recvbuf); diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index 48e7328648..6f8c83a75f 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -295,22 +295,24 @@ udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf, isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t *)handle); isc_region_t region; uint32_t maxudp; + bool free_buf = true; REQUIRE(VALID_NMSOCK(sock)); - /* - * We can ignore the flags; currently the only one in use by libuv - * is UV_UDP_PARTIAL, which only occurs if the receive buffer is - * too small, which can't happen here. - */ +#ifdef UV_UDP_MMSG_CHUNK + free_buf = ((flags & UV_UDP_MMSG_CHUNK) == 0); +#else UNUSED(flags); +#endif /* * If addr == NULL that's the end of stream - we can * free the buffer and bail. */ if (addr == NULL) { - isc__nm_free_uvbuf(sock, buf); + if (free_buf) { + isc__nm_free_uvbuf(sock, buf); + } return; } @@ -331,7 +333,9 @@ udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf, INSIST(sock->rcb.recv != NULL); sock->rcb.recv(nmhandle, ®ion, sock->rcbarg); - isc__nm_free_uvbuf(sock, buf); + if (free_buf) { + isc__nm_free_uvbuf(sock, buf); + } /* * If the recv callback wants to hold on to the handle,