From daf9c643d1ee3ee0f2b00bf9b75966f055e67821 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Thu, 11 Mar 2021 15:22:18 +0300 Subject: [PATCH] QUIC: do not reallocate c->sockaddr. When a connection is created, enough memory is allocated to accomodate any future address change. --- src/event/ngx_event_udp.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/event/ngx_event_udp.c b/src/event/ngx_event_udp.c index 884b1cd51..a15e31f41 100644 --- a/src/event/ngx_event_udp.c +++ b/src/event/ngx_event_udp.c @@ -24,6 +24,7 @@ static ngx_connection_t *ngx_lookup_udp_connection(ngx_listening_t *ls, void ngx_event_recvmsg(ngx_event_t *ev) { + size_t len; ssize_t n; ngx_str_t key; ngx_buf_t buf; @@ -302,7 +303,15 @@ ngx_event_recvmsg(ngx_event_t *ev) return; } - c->sockaddr = ngx_palloc(c->pool, socklen); + len = socklen; + +#if (NGX_QUIC) + if (ls->quic) { + len = NGX_SOCKADDRLEN; + } +#endif + + c->sockaddr = ngx_palloc(c->pool, len); if (c->sockaddr == NULL) { ngx_close_accepted_udp_connection(c); return; @@ -704,13 +713,6 @@ ngx_lookup_udp_connection(ngx_listening_t *ls, ngx_str_t *key, } #endif - if (c->socklen < socklen) { - c->sockaddr = ngx_palloc(c->pool, socklen); - if (c->sockaddr == NULL) { - return c; - } - } - ngx_memcpy(c->sockaddr, sockaddr, socklen); c->socklen = socklen; }