summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_router.c
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-03-13 23:43:12 +0000
committerAndrew Clayton <a.clayton@nginx.com>2023-03-14 17:07:08 +0000
commit172ceba5b60d02cfc3acfb0feb88f415e7837092 (patch)
tree8af64f45baecc08d129e658c36e4e0ef06b75257 /src/nxt_router.c
parent28bdeec614d21d0ff2309431354e8cc389aac208 (diff)
downloadunit-172ceba5b60d02cfc3acfb0feb88f415e7837092.tar.gz
unit-172ceba5b60d02cfc3acfb0feb88f415e7837092.tar.bz2
Router: More accurately allocate request buffer memory.
In nxt_router_prepare_msg() we create a buffer (nxt_unit_request_t *req) that gets sent to an application process that contains details about a client request. This buffer was always a little larger than needed due to allocating space for the remote address _and_ port and the local address _and_ port. We also allocate space for the local port separately. ->{local,remote}->length includes the port number and ':' and also the '[]' for IPv6. E.g [2001:db8::1]:8080 ->{local,remote}->address_length represents the length of the unadorned IP address. E.g 2001:db8::1 Update the buffer size so that we only allocate what is actually needed. Suggested-by: Zhidao HONG <z.hong@f5.com> Cc: Zhidao HONG <z.hong@f5.com> Reviewed-by: Zhidao HONG <z.hong@f5.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/nxt_router.c')
-rw-r--r--src/nxt_router.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 4637cc68..17fe0418 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -5206,8 +5206,8 @@ nxt_router_prepare_msg(nxt_task_t *task, nxt_http_request_t *r,
req_size = sizeof(nxt_unit_request_t)
+ r->method->length + 1
+ r->version.length + 1
- + r->remote->length + 1
- + r->local->length + 1
+ + r->remote->address_length + 1
+ + r->local->address_length + 1
+ nxt_sockaddr_port_length(r->local) + 1
+ r->server_name.length + 1
+ r->target.length + 1