From: Colin Vidal Date: Tue, 18 Nov 2025 09:31:24 +0000 (+0100) Subject: attach socket before async streamdns_resume_processing X-Git-Tag: v9.21.16~40^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c8b517d563141271625605ddc35559f22f613bd;p=thirdparty%2Fbind9.git attach socket before async streamdns_resume_processing Call to `streamdns_resume_processing` is asynchronous but the socket passed as argument is not attached when scheduling the call. While there is no reproducible way (so far) to make the socket reference number down to 0 before `streamdns_resume_processing` is called, attach the socket before scheduling the call. This guard against an hypothetic case where, for some reasons, the socket refcount would reach 0, and be freed from memory when `streamdns_resume_processing` is called. --- diff --git a/lib/isc/netmgr/streamdns.c b/lib/isc/netmgr/streamdns.c index 2da8a63a0aa..9dd8b0aeab6 100644 --- a/lib/isc/netmgr/streamdns.c +++ b/lib/isc/netmgr/streamdns.c @@ -93,6 +93,8 @@ streamdns_closing(isc_nmsocket_t *sock); static void streamdns_resume_processing(void *arg); +static void +async_streamdns_resume_processing(void *arg); static void streamdns_resumeread(isc_nmsocket_t *sock, isc_nmhandle_t *transphandle) { @@ -193,8 +195,9 @@ streamdns_on_complete_dnsmessage(isc_dnsstream_assembler_t *dnsasm, * Process more DNS messages in the next loop tick. */ streamdns_pauseread(sock, transphandle); - isc_async_run(sock->worker->loop, streamdns_resume_processing, - sock); + isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL }); + isc_async_run(sock->worker->loop, + async_streamdns_resume_processing, sock); } return false; @@ -690,6 +693,15 @@ streamdns_resume_processing(void *arg) { streamdns_handle_incoming_data(sock, sock->outerhandle, NULL, 0); } +static void +async_streamdns_resume_processing(void *arg) { + isc_nmsocket_t *sock = (isc_nmsocket_t *)arg; + + streamdns_resume_processing(sock); + + isc__nmsocket_detach(&sock); +} + static isc_result_t streamdns_accept_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { isc_nmsocket_t *listensock = (isc_nmsocket_t *)cbarg;